I would like to toggle a flag on a button push.
btn = io(pi,3)
if btn = 0 then
if flag = 0 then flag = 1
else
if flag = 1 then flag = 0
endif
is there a better / simpler way??
thanks in advance
dwight
Explore... Chat... Share...
Moderator: Mmiscool
btn = io(pi,3)
if btn = 0 then
if flag = 0 then flag = 1
else
if flag = 1 then flag = 0
endif
toggle = 1
button "switch", [switch]
wait
[switch]
toggle = ! toggle
io(po,d2,(abs(toggle))
wait
ledpin = 1 'Use ledpin as your flag variable
buttonpin = 0 'Uses gpio00 flashing button by default, change to suit (needs pullup resistor).
interrupt buttonpin, [PRESSED]
wait
[PRESSED]
if io(laststat,buttonpin) = 0 then gosub [TOGGLE] 'else do nothing
wait
[TOGGLE]
if io(laststat,ledpin) = 1 then io(po,ledpin,0) else io(po,ledpin,1)
return
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]