View Single Post
  #2   Spotlight this post!  
Unread 16-02-2008, 11:15
psy_wombats's Avatar
psy_wombats psy_wombats is offline
Registered User
AKA: A. King
FRC #0467 (Duct Tape Bandits)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Shrewsbury MA
Posts: 95
psy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura about
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;
}
This is a good thing to know how to do, as it is used fairly often. I advise that instead of copy/pasting the code that you read the comments and write a similar routine yourself.