|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Hello, does anyone know how to program in MPLab this thing... We want pwm02 to turn on if p3_sw_trig was hit. Then, if it's hit again, to shut pwm02 off. Basically like an on or off button. Any help would be greatly appreciated. Thank You.
|
|
#2
|
||||
|
||||
|
Re: Toggle Motor On & Off Help.....
This involves storing the last state of your button, something like this:
Code:
void Run_Motor_Button (void)
static unsigned char engage_motor = 0; //Should the motor be on?
static unsigned char last_button_state = 0; //This will be the last position of p3_sw_trig
if (p3_sw_trig && !last_button_state){ //The button is pushed but wasn't last time
engage_motor = !engage_motor //Change what should be happening to the motor
}
last_button_state = p3_sw_trig; //Update the state of the button
if (engage_motor){ //Use the motor if needed
pwm02 = 255;
} else {
pwm02 = 127;
}
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Getting Gear off of Fisher Price Motor | Denman625 | Motors | 2 | 12-02-2008 20:58 |
| Off Season Software for Rack & Roll | Kims Robot | Off-Season Events | 0 | 22-10-2007 14:54 |
| 2005 Off-Season Competitions; A list of what, when, & where | Erin Rapacki | Off-Season Events | 2 | 25-01-2005 14:23 |
| Novi Kick-off & Workshop | Dung H Cao | Thanks and/or Congrats | 0 | 06-01-2002 09:37 |