1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
// 2-dimensional array of row pin numbers:
const int row[8] = {
2,7,19,5,13,18,12,16 };
// 2-dimensional array of column pin numbers:
const int col[8] = {
6,11,10,3,17,4,8,9 };
int matrix[8][8]= {
{1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
};
void setup()
{
//Set each pin to OUTPUT.
for (int thisPin = 0; thisPin < 8; thisPin++)
{
pinMode(col[thisPin], OUTPUT);
pinMode(row[thisPin], OUTPUT);
digitalWrite(col[thisPin], HIGH); //Set each column to positive. (COLUMN SCAN).
}
}
void loop()
{
RefreshScreen();
SetLedPosition();
}
void SetLedPosition()
{
int x;
int y;
GetLedPosition(x,y);
int movex = x;
int movey = y;
x+3;
y+3;
}
void GetLedPosition (int& x, int& y)
{
for (int checkx=0; checkx<8; checkx++)
{
for(int checky=0; checky<8; checky++)
{
if (matrix[checkx][checky] == 1)
{
checkx = x;
checky = y;
}
}
}
}
void RefreshScreen ()
{
for (int xpixel=0; xpixel<8; xpixel++)
{
for ( int ypixel=0; ypixel<8; ypixel++)
{
if (matrix[xpixel][ypixel] == 1)
{
pixel(xpixel,ypixel);
}
}
}
}
void pixel (int x, int y)
{
digitalWrite(row[x], HIGH);
digitalWrite(col[y], LOW);
digitalWrite(row[x], LOW);
digitalWrite(col[y], HIGH);
}
|