Newbie question regarding loops #433
Replies: 7 comments
-
Posted at 2015-06-25 by DrAzzy First argument to setTimeout has to be a function or a string. function: There's another problem there though.... you'll stack up 50 timeouts, which will then all run at once in 5 seconds. That setTimeout() should be outside the loop. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-25 by ukflyer @drazzy The timeout is needed to delay the step otherwise the pattern will complete in a flash, if you will forgive the pun ! Thanks |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-25 by DrAzzy Aaah so you want it to happen after each call to step. (I also misread a bit what your code was doing there) That won't work, because setTimeout() doesn't block. It stores the function and remembers to execute it in 5 seconds, and then the rest of the code continues executing (ie, it acts like setTimeout does in normal javascript). So you'd end up with the loop running almost instantly, and then all timeouts fire off in rapid succession 5 seconds later. You want to use setInterval() instead, and put both functions into the interval (while storing the current animation index in a global variable or object property). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-25 by ukflyer @drazzy Thanks for pointing me in the right direction. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-25 by DrAzzy No problemo |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-26 by ukflyer Okay maybe not the most exciting pattern but here is what I ended up with -
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-26 by Spocki @ukflyer And now stick it on the bumper;-) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-06-25 by ukflyer
Hi,
I apologise in advance for this simple question.
I have just taken delivery of two strings of 50 WS2811 led's.
I can get all the sample code working and I have managed to extend the patterns of blinking but now I would like to try stepping patterns, ie light the first two led's and then step forwards lighting one led at a time and turning off the first led so that only two leds are lit at any one time.
Here is the code that I am playing with -
I know its ugly but I am just playing at the moment.
When I execute this the first two leds light and I get the following error -
Any pointers would be gratefully appreciated.
Beta Was this translation helpful? Give feedback.
All reactions