Non-blocking serial read from thread on Photon

I am using the NeoPixel library to light up 330 leds (several NeoPixel strips soldered together) and I am having an issue with reading Serial via RX TX without blocking the main loop. I want the loop function to contain only the code that is changing the LED colors. It could be vice-versa as well, with the Serial reading from loop, but then i need the color changing function to be non-blocking, as sometimes the pattern will be solid (doesnt need constant updating) versus a rainbow cycle where the colors are constantly being updated.

Thanks

1 Like

Not seeing your code doesn’t help.
If neither of your code blocks (colour change or serial comm) are non-blocking both can run concurrently in loop() on the same thread.

It’s always wise to adopt the non-blocking coding paradigm in your blood before moving on to multi-threading.

A common mistake made be starters is to call strip.show() too frequently.
You’d rather update all LEDs and then call strip.show() only once.
There is also no use in updating the strip more often than your actual colour pattern changes enough to be perceivable.

There are worlds between constantly and the 25Hz limit of perception (unless you want to exploit PoV with moving LEDs, then you need considerably higher refresh rates - probably not with 330 LEDs tho’).

1 Like