Alright so I'm trying to learn arrays. This code uses 3 arrays which each color of leds with their own array. Is there a way that I can make it all into one array and each row of the array could be a color. Also, I'm aware of how messy this code is, what would be a better way to write this same sequence?
Board Type: Arduino UNO
P.S. this is just one sequence that I'm wanting to do.
The sequence for light placement is YRGYRGYRG so this code just makes
each light, light up in a row
int rticker = 0;
int yticker = 0;
int gticker = 0;
const int eachColorNum = 3;
int yLed[eachColorNum] = { 2, 5, 8 };
int rLed[eachColorNum] = { 3, 6, 9 };
int gLed[eachColorNum] = { 4, 7, 10 };
void setup() {
Serial.begin(9600);
for (byte y = 0; y < 3; y++) {
pinMode(yLed[y], OUTPUT);
}
for (byte r = 0; r < 3; r++) {
pinMode(rLed[r], OUTPUT);
}
for (byte g = 0; g < 2; g++) {
pinMode(gLed[g], OUTPUT);
}
}
void loop() {
Serial.println(rticker);
// turn on led Lights
if (yticker < eachColorNum) { // turn on yellow Lights
digitalWrite(yLed[yticker], HIGH);
delay(500);
yticker++;
}
if (rticker < eachColorNum) { //turn on Red Lights
digitalWrite(rLed[rticker], HIGH);
delay(500);
rticker++;
}
if (gticker < eachColorNum) { // turn on Green lights
digitalWrite(gLed[gticker], HIGH);
delay(500);
gticker++;
}
// Turn off led lights
if (yticker == eachColorNum) { // turn off Green lights
for (byte c = 0; c < eachColorNum; c++) {
digitalWrite(yLed[c], LOW);
}
yticker = 0;
}
if (rticker == eachColorNum) { // turn off Green lights
for (byte c = 0; c < eachColorNum; c++) {
digitalWrite(rLed[c], LOW);
}
rticker = 0;
}
if (gticker == eachColorNum) { // turn off Green lights
for (byte c = 0; c < eachColorNum; c++) {
digitalWrite(gLed[c], LOW);
}
gticker = 0;
}
}