I did not completely see thru your code, but mainly, there is a heave function and a much lighter function, each independent of each other and called on individual intervals.
First, though, let's look at the code - especially at the on init:
Every 60 ms, sendData() is invoked,
Every 10 ms, led() is invoked.
If you put console.log into your code, you will see that 5 or 6 times led() runs before sendData() is run the first time. Also, when you put console.log at begin and end as first and last in led() and sendData(), you will notice that one always runs completely before it runs again or something else runs (completely).
To make it bette visible, change the time to a least the 10 fold: 600 and 100 ms, that way Espruino can - most of the time - take care of what it is told to do before a new time event happens and the same ore something else should happen.
Even though both of your functions called at intervals have nothing to do with each other, they can have an impact on each other. Do you know how much time it take to execute sendData()? Adding getTime() at begin and end with delta calculation will tell you.,
© Espruino, powered by microcosm.
Report a problem