|
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;
}
|