As the title says... Chat on...

User avatar
By cherowley
#11662 Hi!

Has anyone got an example code for detecting long/short "button presses" on a gpio line?

I can't seem to get it working what with debouncing and seemingly missed interrupts..

Cheers!

Che
User avatar
By andrew melvin
#11665 This might work. I didn't use if for this purpose, but if you print(du) you can see the pulse width of the press. then use the if du > x to filter. should work!



Code: Select allcount = 0
pulse1 = 0
du = 0
gpio.mode(4,gpio.INT,gpio.PULLUP)


function pin1cb(level)
du = tmr.now() - pulse1
if du > 10000000 then

 count = count + 1

end
pulse1 = tmr.now()
if level == 1 then gpio.trig(4, "down") else gpio.trig(4, "up") end
end
User avatar
By cherowley
#11667 Thanks, I'll give that a go.

Have you or anyone else experienced missed interrupts as this seems to be the problem - sometimes it just doesn't seem to detect rising/falling edges?

I'm using a esp-01 gpio0 with a 4.7k pull up.