digitalPulse and setTimeout doesn't work #1419
Replies: 3 comments
-
Posted at 2020-07-28 by @gfwilliams Ahh - pretty sure you're hitting: http://www.espruino.com/Reference#l__global_digitalPulse
So it's doing the pulses, but it's queueing them up to happen at pretty much the same time, in the background. If you did:
It'd likely do what you're expecting, but it's far from ideal. What you were attempting with the timeout would have been best, but there were just somes issue with your code:
Instead something like this should work fine:
Normally I wouldn't recommend Another slightly more efficient solution would be to just have a single function that runs over and over:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-28 by BootySnorkeler @gfwilliams Oh my goodness thank you so much! It works like a charm :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-28 by @gfwilliams You're just executing a string of code, so you're just adding strings together to make one big bit of text (which happens to also be a JavaScript command) - it's like you'd have if you were working with Strings in any language:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2020-07-28 by BootySnorkeler
Hi,
I'm trying to write a simple LED animation for a 7-segment display. It will light up a segment, then another one, then another one, until all are lit up, then dim a segment, then dim another one, etc. The code is (supposed to be) very simple. For reference, I'm using an MDBT42Q module with a 32khz crystal added on P0 and P1 with 22pf caps. I don't think it should affect my code.
and well, the code works as if the digitalPulse()es aren't even there. Everything happens very quickly so the LEDs just light up and off in a fraction of a second. I honestly have no idea why this isn't working as the other digitalPulses in the rest my code work just fine. I have other LED animations that use digitalPulse() in my code and those animations have no problem.
So I tried using setTimeout(). I believe it's like so, but I might be wrong:
this one doesn't work either. So I tried another method:
And same results.
This has been driving me absolutely bonkers for the past few hours so any help would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions