Created
October 5, 2011 14:52
-
-
Save TAUTIC/1264617 to your computer and use it in GitHub Desktop.
LED Matrix Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int lastFrame = 4; //Number of frames in the animation sequence | |
const boolean image[4][8][20] = | |
{ | |
{ | |
{1,1,0,0,1,1,0,0,1,1,1,1,0,0,0,1,1,1,1,1}, | |
{1,1,0,0,1,1,0,0,1,1,1,0,0,0,0,1,1,1,1,1}, | |
{1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1}, | |
{1,1,1,1,0,0,1,1,1,1,0,0,0,1,1,1,0,1,1,0}, | |
{1,0,1,1,1,1,1,1,0,1,0,0,0,0,1,1,1,1,1,1}, | |
{1,0,0,1,1,1,1,0,0,1,1,0,0,0,0,1,1,1,1,1}, | |
{1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,1}, | |
{1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1} | |
}, | |
{ | |
{1,1,0,0,1,1,0,0,1,1,1,1,0,0,0,1,1,1,1,1}, | |
{1,1,0,0,1,1,0,0,1,1,1,0,0,0,0,0,1,1,1,1}, | |
{1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1}, | |
{1,1,1,1,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,1}, | |
{1,0,1,1,1,1,1,1,0,1,0,0,0,0,0,1,1,1,1,1}, | |
{1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,1,1}, | |
{1,0,0,1,1,1,1,0,0,1,1,1,0,0,0,1,1,1,1,1}, | |
{1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1} | |
}, | |
{ | |
{1,1,0,0,1,1,0,0,1,1,1,1,0,0,0,1,1,1,1,1}, | |
{1,1,0,0,1,1,0,0,1,1,1,0,0,0,0,0,1,1,1,1}, | |
{1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1}, | |
{1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1}, | |
{1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,1}, | |
{1,0,0,1,1,1,1,0,0,1,1,0,0,0,0,0,1,1,1,1}, | |
{1,0,0,1,1,1,1,0,0,1,1,1,0,0,0,1,1,1,1,1}, | |
{1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1} | |
}, | |
{ | |
{1,1,0,0,1,1,0,0,1,1,1,1,0,0,0,1,1,1,1,1}, | |
{1,1,0,0,1,1,0,0,1,1,1,0,0,0,0,0,1,1,1,1}, | |
{1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1}, | |
{1,1,1,1,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,1}, | |
{1,0,1,1,1,1,1,1,0,1,0,0,0,0,0,1,1,1,1,1}, | |
{1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,1,1}, | |
{1,0,0,1,1,1,1,0,0,1,1,1,0,0,0,1,1,1,1,1}, | |
{1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1} | |
} | |
}; | |
const int row[20] = {8,9,38,11,12,13,34,35,36,37,2,3,4,5,6,7,39,40,41,A1}; | |
const int col[8] = {26,27,28,29,30,31,32,33}; | |
const int matrixWidth = 20; | |
int currentFrame = 0; | |
int cycles = 0; | |
int cyclesPerFrame = 20; | |
void setup(){ | |
for(int p = 0; p < 8; p++) { | |
pinMode(col[p], OUTPUT); | |
digitalWrite(col[p], HIGH); | |
} | |
for(int q = 0; q < matrixWidth; q++) { | |
pinMode(row[q], OUTPUT); | |
digitalWrite(row[q], HIGH); | |
} | |
} | |
void loop(){ | |
for (int x=0;x<8;x++) | |
{ | |
for (int r=0;r<matrixWidth;r++) | |
{ | |
digitalWrite(row[r], image[currentFrame][x][r]); | |
} | |
digitalWrite(col[x], LOW); | |
delay(1); | |
digitalWrite(col[x], HIGH); | |
} | |
//This code helps with frame management. | |
cycles++; | |
if (cycles > cyclesPerFrame) { | |
(currentFrame == lastFrame - 1) ? currentFrame=0 : currentFrame++; //If at last frame, reset counter else increment | |
cycles = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment