I wrote this compressor control code after playing a few too many Zelda games. My students found it very amusing and it is actually in the robot (and works quite well, debounce helps).
Code:
/*******************************************************************************
* FUNCTION NAME: Magic_Wind
* PURPOSE: Creates magic wind (air pressure) to blow into (confidential info edited out) of the robot.
* Minimizes rapid wind changes (debounces).
* CALLED FROM: Process_Data_From_Master_uP
* PARAMETERS: none
* RETURNS: void
*******************************************************************************/
//constants
#define Change_in_Wind 15
//aliases
#define Rumble_Pak relay1_fwd //compressor (until fuse blows)
#define Rumble_Gnd relay1_rev //compressor (always 0, unless
//I choose to decompress the bot)
#define Wind_Waker rc_dig_in18 //pressure switch
//global var
unsigned char Old_Wind_Waker = 1;
unsigned char Wind_Timer = Change_in_Wind;
void Magic_Wind()
{
if (Wind_Timer == Change_in_Wind)
Rumble_Pak = !Wind_Waker;
else if (Wind_Timer < Change_in_Wind)
Wind_Timer++;
if (Wind_Waker != Old_Wind_Waker)
Wind_Timer = 0;
Rumble_Gnd = 0;
Old_Wind_Waker = Wind_Waker;
}