Duplicate of this question
I'm trying to drive an 8x8 LED matrix with an arduino nano, but I can't get the LEDs to display what I tell it to.
I'm using this LED Matrix
Here's my code:
int row1 = 2;
int row2 = 3;
int row3 = 4;
int row4 = 5;
int row5 = 6;
int row6 = 7;
int row7 = 8;
int row8 = 9;
int col1 = 10;
int col2 = 11;
int col3 = 12;
int col4 = 18;
int col5 = 14;
int col6 = 15;
int col7 = 16;
int col8 = 17;
void setup() {
int i;
for(i = 2; i <= 18; i++) {
pinMode(i,OUTPUT);
}
for(i = 2; i <= 9; i++) {
digitalWrite(i, HIGH);
}
}
void loop() {
int display [8][8] = {
{1,0,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,0,1,0,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0},
{0,0,0,0,0,1,0,0},
{0,0,0,0,0,0,1,0},
{0,0,0,0,0,0,0,1}
};
updateScreen(display);
}
void updateScreen(int screen[8][8]) {
Serial.begin(9600);
int i;
for (i = row1; i <= row8; i++) {
Serial.println(i-1);
digitalWrite(i, LOW);
digitalWrite(col8, screen[i-2][0]);
Serial.print(screen[i-2][0]); Serial.print("|");
digitalWrite(col7, screen[i-2][1]);
Serial.print(screen[i-2][1]); Serial.print("|");
digitalWrite(col6, screen[i-2][2]);
Serial.print(screen[i-2][2]); Serial.print("|");
digitalWrite(col5, screen[i-2][3]);
Serial.print(screen[i-2][3]); Serial.print("|");
digitalWrite(col4, screen[i-2][4]);
Serial.print(screen[i-2][4]); Serial.print("|");
digitalWrite(col3, screen[i-2][5]);
Serial.print(screen[i-2][5]); Serial.print("|");
digitalWrite(col2, screen[i-2][6]);
Serial.print(screen[i-2][6]); Serial.print("|");
digitalWrite(col1, screen[i-2][7]);
Serial.println(screen[i-2][7]);
delay(1);
blank();
digitalWrite(i, HIGH);
}
}
void blank() {
digitalWrite(col1, LOW);
digitalWrite(col2, LOW);
digitalWrite(col3, LOW);
digitalWrite(col4, LOW);
digitalWrite(col5, LOW);
digitalWrite(col6, LOW);
digitalWrite(col7, LOW);
digitalWrite(col8, LOW);
}
And here is the output:
1
1|0|0|0|0|0|0|0
2
0|1|0|0|0|0|0|0
3
0|0|1|0|0|0|0|0
4
0|0|0|1|0|0|0|0
5
0|0|0|0|1|0|0¾j
6
0|0|0|0|0|1|0|0
7
0|0|0|0|0|0|1|0
8
0|0|0|0|0|0|0|1
So I can tell that the error (probably) isn't my wiring, because those array values are clearly wrong, I have no idea where the ¾j
is coming from.
.
instead of,
in my array declaration. Thanks anyways :) – user168057 Mar 8 '14 at 4:39