Quote:
Originally Posted by dboisvert
I am trying to accomplish a simple button task. When someone pushes a button I want it to keep doing the action (IE In this case "Relay Forward" & "Relay Reverse") until the microswitch is activated. Right now it stops as soon as you release the button.
What the code looks like right now is this
Code:
if button1 == 1 & microswitch1 = 0
Relay Forward
else if button2 == 1 & microswitch2 = 0
Relay Reverse
else
Relay Off
Any suggestions?
|
int dir=0;//at the top
...
loop//your while loop
..
if (button1 ==1 && !(microswitch1==1))//if button1 pressed and microsw ! pressed
dir=1;
else if (button2==1 && !(microswitch2==1))//if button2 pressed and microsw ! pressed
dir=-1;
else if (microswitch1 ==1 || microswitch2 ==1)//if microsw pressed
dir=0;
//otherwise do nothing to the value
relay.Set((float)dir);//set the new (or old )value
...
end loop
...