Could someone please explain me how are the IDs allocated? Or even better why it's not like I thought? :)
In this code below I would expect the ledTimer to get the same value (ID) over and over again but that doesn't happen.
ledTimer
var btnPin = BTN; var ledPin = LED1; var ledTimer = null; digitalWrite(ledPin, 0); var btnWatcher = setWatch(function () { if (ledTimer) { clearTimeout(ledTimer); ledTimer = null; } digitalWrite(ledPin, 1); console.log("before: " + ledTimer); ledTimer = setTimeout(function () { digitalWrite(ledPin, 0); ledTimer = null; }, 4000); console.log("after: " + ledTimer); }, btnPin, {repeat: true, edge: "rising", debounce: 70});
Now when I press the button every 5 seconds I get what I expected:
before: null after: 2 before: null after: 2 ...and so on
But when I press the button every 3 seconds then it's not what I expected:
before: null after: 2 before: null after: 4 ...and +2 every time
@graf started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Could someone please explain me how are the IDs allocated? Or even better why it's not like I thought? :)
In this code below I would expect the
ledTimer
to get the same value (ID) over and over again but that doesn't happen.Now when I press the button every 5 seconds I get what I expected:
But when I press the button every 3 seconds then it's not what I expected: