I made a homemade 3x3 LED array and each LED is attached to a Digital output on the Arduino Nano I have (D2-D10).
I originally wrote a program for it that, for every image I displayed (be it a plus, a x, a spiral, whatever) it would turn each LED on and off in a specific order. It worked but it used a MASSIVE amount of space (less than 10 graphics totaling less than 20 seconds used up 20% of the 32kb of memory!) On top of that, finding any errors in the code was a nightmare.
I was looking to make it much more efficient, and the general idea I am getting is that I need the For Loop, but no matter how many videos I watch and tutorials I read I can't get my head wrapped around it.
Say, for example, I wanted to make a plus pattern appear, then disappear 500ms later.
The plus pattern would use LEDs 2, 5, 6, 7, 9 (D3, D6, D7, D8, D9 pins).
How would I go about this?
Any advice would be appreciated.
Here's what I have so far. I have it set up to turn on when I push the push button.
I copied the first For Loop from another code I found on the internet, but I don't really "understand it"... I just changed the array number from the original 6 to 9 which is my number of LEDs.
int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
int pinCount = 9;
void setup() {
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
pinMode (11, INPUT);
}
void loop() {
}