NeoPixels and blocking in a for...loop

I'm running 60 NeoPixels off of an Adafruit Feather 32u4 and playing with some of the example animations. I'm connecting to the board over BLE, and everything works fine..Except...

On a few of the animations, the for loop could be several hundred iterations, and it's blocking the loop() from reading input packets from Bluetooth. I have to wait for those animation to reach a starting over point before my input are recognized to switch to a different one.

Question is, how do I make sure I can still get timely read of the input buffer while those nested, long animations are running so that the board is responsive to changes?

Change out the for loop to a do..while? Or something else entirely?

Thanks!

Heat

That’s the problem with blocking code or code that turns off interrupts.

You can rewrite the library to look for events but that would take a fair amount of work.

heatmizuh:
I'm running 60 NeoPixels off of an Adafruit Feather 32u4 and playing with some of the example animations. I'm connecting to the board over BLE, and everything works fine..Except...

On a few of the animations, the for loop could be several hundred iterations, and it's blocking the loop() from reading input packets from Bluetooth. I have to wait for those animation to reach a starting over point before my input are recognised to switch to a different one.

So you need to "unwind" the "for" loop (or loops) - turn it (them) inside out. That is exactly the purpose of having a main "loop()" in the code. Then the Bluetooth input processing - which does not use a "for" or "while" loop itself - will be part of the loop.

heatmizuh:
Question is, how do I make sure I can still get timely read of the input buffer while those nested, long animations are running so that the board is responsive to changes?
Change out the for loop to a do..while? Or something else entirely?

So you imagine a "do" loop is different to a "for" loop? :astonished:

You unwrap a for loop by setting a static variable as the loop counter variable. Then you do the code inside the for loop, finally you increment the loop counter variable and check that it has not exceeded the limit. Then you return. So in effect you do only one iteration of the for loop before returning to the main loop function allowing you to check your control.

See reply #3 in this recent post of mine for an example of this:-

The theaterChaseRainbow() function is a classic example of doing this for two nested for loops with loop variables j and q.