// only one led color will turn on at a time either blue or red
int led[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
// red and blue
int ledCol[3][3][2] = {
{{0, 1}, {1, 0}, {0, 1}},
{{1, 0}, {0, 1}, {1, 0}},
{{0, 1}, {1, 0}, {0, 1}}
};
byte comPins[3] = {13, 12, 11};
byte bluePins[3] = {A3, A4, A5};
byte redPins[3] = {A0, A1, A2};
void ledDrive() {
for (int row = 0; row < 3; row++) {
digitalWrite(comPins[row], LOW);
for (int col = 0; col < 3; col++) {
if (ledCol[row][col][0] == 1) {
digitalWrite(redPins[col], HIGH);
} else {
digitalWrite(redPins[col], LOW);
}
if (ledCol[row][col][1] == 1) {
digitalWrite(bluePins[col], HIGH);
} else {
digitalWrite(bluePins[col], LOW);
}
}delay(1);
digitalWrite(comPins[row], HIGH);
}
}
void setup() {
Serial.begin(9600);
Serial.println("");
for (int c = 0; c < 3; c++) {
pinMode(comPins[c], OUTPUT);
pinMode(bluePins[c], OUTPUT);
pinMode(redPins[c], OUTPUT);
digitalWrite(comPins[c], HIGH);
}
}
void loop() {
ledDrive();
}