|
Remember that p1_sw_top will be 1 the entire time the switch is pressed. So, if you hold it down for 1 second, the relay will change back and forth about 40 times. What I do is store a bit (i call it p1_sw_top_last) that stores the state of the button last cycle. When p1_sw_top &~ p1_sw_top_last , then the button has just been pressed, so perform actions. Try this out:
when declaring variables:
=================================
p1_sw_top_last VAR bit
p1_sw_top_last = 0
in the main loop:
=================================
if NOT (p1_sw_top &~ p1_sw_top_last) then skipThis1:
if relay1_rev then fwd1:
relay1_fwd = 0
relay1_rev = 1
goto skipthis
fwd1:
relay1_fwd = 1
relay1_rev = 0
skipThis1:
p1_sw_top_last = p1_sw_top
Im gonna be testing this out tomorrow, so I'm not sure if it works.
|