View Single Post
  #3   Spotlight this post!  
Unread 01-02-2007, 22:44
tdlrali tdlrali is offline
Registered User
FRC #0469 (Las Guerrillas)
Team Role: Programmer
 
Join Date: Sep 2006
Rookie Year: 2006
Location: MI
Posts: 377
tdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud of
Re: making a trigger a toggle

Code:
static char p1_trig_state = 1;
static unsigned char p1_trig_pressed = 0;

if(p1_sw_trig && !p1_trig_pressed) {
    p1_trig_state *= -1;
    p1_trig_pressed = 1;
}
else if(!p1_sw_trig)
    p1_trig_pressed = 0;

if(p1_trig_state==1)
    pwm01 = 255;
else
    pwm01 = 127;
with any toggle code, if your output switches state rapidly a few times after your input is pressed, you might need to add a little delay to debounce the input