Should printing to serial or grabbing led values slow down an animation significantly? I was trying to grab data to plot what beatsin8() is doing and found that it really messed up the animation when I inserted a for loop to print each pixel value. I don’t have the exact code on hand, but it was something like:
I also tried putting it inside of EVERY_N_MILLISECONDS without much change. When I comment out the print statement it runs nice and smooth. With it, it starts mostly okay and after a few trips back and forth it seems like it’s skipping multiple pixels.
This is with 28 leds, for a size reference (not sure how long it takes to evaluate that for loop/printing).
You are looking at writing out a out 196 bytes per frame of serial data (up to 7 bytes times 28 leds), or 1586 bits. At 57600bps, that will take you almost 28ms to write out the data for each frame, so your every 20ms effectively becomes more like every 50ms.
So if I had the printing inside the millisecond statement and bumped the delay, it would work much better? I was just hoping to make a visualization of the data, so technically I don’t need it running at the desired rate; it doesn’t matter how long it would take to collect.
Thanks for confirming is an issue! I was sort of hoping it was as simple as “serial is slow” !
This type of verbose printing is much faster when you have native USB. Teensy, Leonardo, and the native ports on Due and Zero are native USB. On most other boards, and on the programming ports of Due & Zero, it’s very slow serial.