How to write a program to turn LED ON when the button is pressed and let it ON when the button is released, and then turn LED OFF when the button is pressed and let it OFF when the button is released?The code that I have bellow does not work. BeforeStart OldButton≔ False State≔ False ////////////////////////////////////////////////////// Thread_2 Button≔digital_in[2] LED≔digital_out[1] If (Button≟ True ) and (OldButton≟ False ) If State≟ False Set DO[1]=On State≔ True Else Set DO[1]=Off State≔ False OldButton≔ True ElseIf (Button≟ False ) and (OldButton≟ True ) OldButton≔ False sync()
How to write a program to turn LED ON when the button is pressed and let it ON when the button is released, and then turn LED OFF when the button is pressed and let it OFF when the button is released?
The code that I have bellow does not work.
//////////////////////////////////////////////////////
Thread_2
Button≔digital_in[2]
LED≔digital_out[1]
If (Button≟ True ) and (OldButton≟ False )
If State≟ False
Set DO[1]=On
State≔ True
Else
Set DO[1]=Off
State≔ False
OldButton≔ True
ElseIf (Button≟ False ) and (OldButton≟ True )
OldButton≔ False
sync()