So it is looping forever toggling the state of the pins. It is also adding new timeouts, faster than they can be executed.
The timeout calls are a callback. This means that pause() will be called 20 milliseconds later, however the next statement digitalWrite(B4, 1); gets written straight away - it does not wait 20ms before doing that.
To achieve what you want - you will need to chain calls so that the next action occurs in a call back - not directly.
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.
I think you are expecting your
setTimeout('pause()', 20);
to delay the running of the code for 20 milliseconds.....What you have written is basically this:
So it is looping forever toggling the state of the pins. It is also adding new timeouts, faster than they can be executed.
The timeout calls are a callback. This means that
pause()
will be called 20 milliseconds later, however the next statementdigitalWrite(B4, 1);
gets written straight away - it does not wait 20ms before doing that.To achieve what you want - you will need to chain calls so that the next action occurs in a call back - not directly.
I hope this helps.