I have an Arduino and am trying to find the most efficient way to animate pixels in an array. The array is represented by 3 arrays of 30 uint8_t s. (30 pixels * R + G + B levels 0-255).
What is the best way to move pixels across an array independently? This is limited memory memory (2 KB of RAM), and the array occupies 720 bytes. At first I tried to use an array for each pixel and ran out of memory. The second implementation is used if assertions, and it works well, but it is very tedious to create new templates. I am looking for a way to solve a problem that may be better than I am solving it now.
Here is an example of a template that I would like to animate.
X moves forward 1 each cycle. Y moves forward 3 places then back 2. Z moves backwards 3 places each cycle. |_|X|_|_|_|_|_|_|_|_|_|_|_|_|Y|_|_|_|_|_|_|_|_|_|_|_|_|_|_|Z| |_|_|X|_|_|_|_|_|_|_|_|_|_|_|_|_|_|Y|_|_|_|_|_|_|_|_|Z|_|_|_| |_|_|_|X|_|_|_|_|_|_|_|_|_|_|_|Y|_|_|_|_|_|_|_|Z|_|_|_|_|_|_|
And here is the code I would use.
void animateScene1() { for(int i = 0; i <= numPixels; i++) { setColor(i, X); if(i < 15) { if(i % 2 == 0) setColor((i+15)+3), Y); else setColor((i+15)-2), Y); } if(i < 10) setColor(numPixels-3*i, Z); } }
Any ideas on better ways?
source share