2
Row-Column Scanning an 8x8 LED matrix with X-Y input
4
This example controls an 8x8 LED matrix using two analog inputs
10
This example works for the Lumex LDM-24488NI Matrix. See
11
http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf
12
for the pin connections
14
For other LED cathode column matrixes, you should only need to change
15
the pin numbers in the row[] and column[] arrays
23
* Digital pins 2 through 13,
24
* analog pins 2 through 5 used as digital 16 through 19
26
* center pins are attached to analog pins 0 and 1, respectively
27
* side pins attached to +5V and ground, respectively.
29
http://www.arduino.cc/en/Tutorial/RowColumnScanning
31
see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
35
// 2-dimensional array of row pin numbers:
37
2,7,19,5,13,18,12,16 };
39
// 2-dimensional array of column pin numbers:
43
// 2-dimensional array of pixels:
52
// initialize the I/O pins as outputs:
54
// iterate over the pins:
55
for (int thisPin = 0; thisPin < 8; thisPin++) {
56
// initialize the output pins:
57
pinMode(col[thisPin], OUTPUT);
58
pinMode(row[thisPin], OUTPUT);
59
// take the col pins (i.e. the cathodes) high to ensure that
61
digitalWrite(col[thisPin], HIGH);
64
// initialize the pixel matrix:
65
for (int x = 0; x < 8; x++) {
66
for (int y = 0; y < 8; y++) {
81
// turn off the last position:
83
// read the sensors for X and Y values:
84
x = 7 - map(analogRead(0), 0, 1023, 0, 7);
85
y = map(analogRead(1), 0, 1023, 0, 7);
86
// set the new pixel position low so that the LED will turn on
87
// in the next screen refresh:
92
void refreshScreen() {
93
// iterate over the rows (anodes):
94
for (int thisRow = 0; thisRow < 8; thisRow++) {
95
// take the row pin (anode) high:
96
digitalWrite(row[thisRow], HIGH);
97
// iterate over the cols (cathodes):
98
for (int thisCol = 0; thisCol < 8; thisCol++) {
99
// get the state of the current pixel;
100
int thisPixel = pixels[thisRow][thisCol];
101
// when the row is HIGH and the col is LOW,
102
// the LED where they meet turns on:
103
digitalWrite(col[thisCol], thisPixel);
104
// turn the pixel off:
105
if (thisPixel == LOW) {
106
digitalWrite(col[thisCol], HIGH);
109
// take the row pin low to turn off the whole row:
110
digitalWrite(row[thisRow], LOW);