/* Initialize these variables at the top of the user_routines.c file */ unsigned char toggled = 0; unsigned char previous_toggle = 0; -------------------------------------------------------------------------------- /* Place this function in user_routines.c */ /******************************************************************************* * FUNCTION NAME: triggerToggle * PURPOSE: Tests if a button has just been pressed. This way, if a button * is held down for more than one program loop, then the program * won't think that it has just been pressed again. This should * only be used if a button is used as a toggle switch. i.e. If * holding the trigger button is supposed to raise an arm using * motors, this would not work because the button cannot be * continuously pressed. * * CALLED FROM: this file * ARGUMENTS: void * RETURNS: none *******************************************************************************/ void triggerToggle() { if (p1_sw_trig == 0 & previous_toggle == 0) /* Tests if the trigger button on { Port 1 has just been pressed */ toggled = 1; /* Button has been pressed */ } else { toggled = 0; /* Button has not been pressed */ } previous_toggle = p1_sw_trig; /* Sets previous_toggle value */ } -------------------------------------------------------------------------------- /* Place this code in the Default_Routine() of user_routines.c */ triggerToggle(); /* Runs triggerToggle function */ if (toggled) /* Button was pressed */ { /* Code if button is pressed */ } else /* Button not pressed */ { /* Code if button is not pressed */ }