interrupt.lua 627 B

1234567891011121314151617181920212223242526272829
  1. gpio.mode(6, gpio.INT, gpio.PULLUP)
  2. delay = 0
  3. setupStarted = 0
  4. function buttonHandler(level)
  5. x = tmr.now()
  6. if x > delay then
  7. --button has been debounced
  8. delay = tmr.now()+50000
  9. tmr.delay(2000)
  10. level = gpio.read(6)
  11. print("handler called with level: "..level)
  12. if level == 0 then
  13. --button pressed down initially
  14. tmr.alarm(4, 2000, 0, function()
  15. setupStarted = 1
  16. dofile("wifiSetup.lua")
  17. end
  18. )
  19. else
  20. tmr.stop(4)
  21. --button released
  22. if setupStarted == 0 then
  23. dofile("sendYo.lua")
  24. end
  25. end
  26. end
  27. end
  28. gpio.trig(6, "both",buttonHandler)