Im having a little difficulty with a button i need for my project.
Its very simple, as described here
it has no push-no push, its just clickable.
i made a circuit from 3v3 to the button, and from the button to pin5.
I also, just for understanding, added two leds, at pins 8 & 9.
local times = time(); local state = 0; function ledControl() { times = time() - times; if (times > 1000) { if (state == 0) { state = 1; } else { state = 0; } if (state == 1) { hardware.pin8.write(1); hardware.pin9.write(0); } else { hardware.pin8.write(0); hardware.pin9.write(1); } times = time(); server.log("ledControl"); } } hardware.pin5.configure(DIGITAL_IN_PULLDOWN, ledControl);
at the moment, what that happens is that sometimes pressing causes color to go red -> green,
which is ok, beacuse its what i wanted…1 callback.
but sometimes it reads 1 physical click as 2, generating two callbacks and therefore led is red -> green -> red
Is there any mechanism i can have only 1 callback, somehow to ignore two clicks very close one to the other?
Or should i just create another variable for seeing last time it clicked, and if its very small time difference, to ignore it in the second callback?
Edit: I tried adding time but it still sometimes reads a click as 2 callbacks and sometimes as only 1.
can anyone advice?