Thread: toggle switch
View Single Post
  #1   Spotlight this post!  
Unread 16-01-2006, 15:02
Windward's Avatar
Windward Windward is offline
Registered User
FRC #1452
Team Role: Programmer
 
Join Date: Nov 2005
Rookie Year: 2004
Location: So Cal
Posts: 88
Windward is an unknown quantity at this point
toggle switch

We were setting up a toggle switch so that when you press a button (p1_sw_trig) it activates a spike (relay1_fwd) and when you press the button again it deactivates it. I will also use this for other things in the programming code, such as a manual overide for the auto tracking.


int switch1, switch2, initVar, printCount, switch1Count, switch2Count;

switch1 = SWITCH1; // port1 trig
switch2 = SWITCH2; // port1 top

if(initVar !=1) // initialize variables
{
printCount = 0;
}

printf("switch1 = %d", switch1);
printf("switch2 = %d", switch2);

if(switch1 == 1) // if switch1 pressed
{
if(switch1Count != 1) // not forward, so set forward
{
switch1Count = 1;
}
else // forward, so set back
{
switch1Count = 0;
}
}

printCount++;
if(printCount > 100) // decreases amount of printfs
{
printf("switch1 = %d", switch1);
printf("switch1Count = %d", switch1Count);
printCount = 0;
}
if(switch1Count == 1)
{
relay1_fwd = 1;
switch1Count = 1;
if1 = 1;
}
if(switch1Count == 0)
{
relay1_rev = 1;
switch1Count = 2;
}