8X8 Matrix

int latchpin = 8; // connect to pin 12 on the ‘595
int clockpin = 12; // connect to pin 11 on the ‘595
int datapin = 11; // connect to pin 14 on the ‘595

int matrixrow[8] = {1,2,4,8,16,32,64,128};
int matrixcolumn[8] = {1,2,4,8,16,32,64,128};

//int matrixrow[8] = {128,64,32,16,8,4,2,1};
//int matrixcolumn[8] = {128,64,32,16,8,4,2,1};

void pixeldisplay(int row, int column, int holdtime)
// turns on and off a pixel at row, column – with delay ‘holdtime’
{
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, matrixcolumn[column-1]); // sets the digit to address
shiftOut(datapin, clockpin, MSBFIRST, matrixrow[row-1]); // clears the digit
digitalWrite(latchpin, HIGH);
delay(holdtime);
}

void rowdisplay(int row, int holdtime)
// turns on and off a row of LEDs with delay ‘holdtime’
{
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 255); // we want all the cathodes on, which is 11111111 in binary, 255 decimal
shiftOut(datapin, clockpin, MSBFIRST, matrixrow[row-1]); // clears the digit
digitalWrite(latchpin, HIGH);
delay(holdtime);
}

void columndisplay(int column, int holdtime)
// turns on and off a column of LEDs with delay ‘holdtime’
{
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, matrixcolumn[column-1]);
shiftOut(datapin, clockpin, MSBFIRST, 255); // we want all the anodes on, which is 11111111 in binary, 255 decimal
digitalWrite(latchpin, HIGH);
delay(holdtime);
}

void setup()
{
pinMode(latchpin, OUTPUT);
pinMode(clockpin, OUTPUT);
pinMode(datapin, OUTPUT);
}

void loop()
{
for (int a=1; a<9; a++)
{
for (int b=1; b<9; b++)
{
pixeldisplay(a,b,150);
}
}
// for (int a=1; a<9; a++)
// {
// for (int b=1; b<9; b++)
// {
// pixeldisplay(b,a,50);
// }
// }
// for (int zz=1; zz<11; zz++)
// {
// for (int a=1; a<9; a++)
// {
// rowdisplay(a, 50);
// }
// for (int a=1; a<9; a++)
// {
// columndisplay(a, 50);
// }
// }
}

Advertisements

Your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s