Tuesday, October 4, 2016

Detect an Interrupt on NodeMCU ESP8266

This lets you detect an interrupt and take action off of it.


-- use pin 1 as the input pulse width counter
local pin, pulse1
pin = 5
pulse1 = tmr.now()

gpio.mode(pin, gpio.INT, gpio.PULLUP)

function pin1cb(level)
  local pulse2 = tmr.now()
  print( level, pulse2 - pulse1 )
  pulse1 = pulse2
  -- gpio.trig(pin, level == gpio.HIGH  and "down" or "up")
  gpio.trig(pin, "both")
end

gpio.trig(pin, "both", pin1cb)
print("setup trigger")

No comments:

Post a Comment