I got my first Uno a few weeks ago. I've been a web developer for many years, but have never done C/C++ or electronics before.
Note: the demo shows a large matrix, but the LEDs will only show one row of that, 2-3 rows from the bottom.
The Arduino sketch in its current form can be seen at LED Fire Arduino sketch - Pastebin.com. This version is set up as a speed test; all it does is calculate the canvas values and report how long each iteration of
loop() takes to execute. As you can see from the comments in the code, I've already eliminated the
float operations (and reduced
max_y from 5 to 3), which reduced the iteration time from ~70ms to ~40ms, however, the execution time currently varies from 33ms to 49ms. I suspect most of the variance comes from
max_x is 40 because that's how many pixels I have room for using a 60/meter strip.
Having read that
memcpy() is slow, I spent an afternoon learning about pointers and made a version of this that manipulated pointers into the
canvas array rather than use
memcpy() was faster overall.
What's left to do is:
- Parse serial input coming from Bluetooth (I don't have a shield yet), which will likely be very short commands such as "H25\n" (heat = 25) and "I70\n" (intensity = 70).
- Send the RGB values out to the LED strip.
I'm looking for ways to squeeze more efficiency out of the existing code, and to stabilize the execution time. If the final, fully-functional code can't be made to iterate in 50ms or less, I feel there's no point in controlling the speed parameter.
If that speed is simply beyond the capabilities of an Uno, then I think my alternative is to switch up to a Mega and have it drive 3 strips or 40 pixels, although I suspect that I wouldn't be fully utilizing a Mega. It kinda makes me wish there was a board somewhere in between, with a clock speed in the 32-64 MHz range.
I have hardware questions also, which don't strictly belong here.