interrupt.lua 579 B

123456789101112131415161718192021222324252627
  1. gpio.mode(4, 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. print("handler called with level: "..level)
  9. delay = tmr.now()+50000
  10. if level == 1 then
  11. --button pressed down initially
  12. tmr.alarm(4, 2000, 0, function()
  13. setupStarted = 1
  14. dofile("wifiSetup.lua")
  15. end
  16. )
  17. else
  18. tmr.stop(4)
  19. --button released
  20. if setupStarted == 0 then
  21. dofile("sendYo.lua")
  22. end
  23. end
  24. end
  25. end
  26. gpio.trig(4, "both",buttonHandler)