Tutorial.RowColumnScanning History

Hide minor edits - Show changes to output

May 23, 2013, at 05:20 PM by Alberto Cicchi -
Changed lines 12-13 from:
These can be very useful displays. To control a matrix, you connect both its rows and columns to your microcontroller. The columns are connected to the LEDs anodes (see Figure 1), so a column needs to be high for any of the LEDs in that column to turn on. The rows are connected to the LEDs cathodes, so the row needs to be low for an individual LED to turn on. If the row and the column are both high or both low, no voltage flows through the LED and it doesn’t turn on.
to:
These can be very useful displays. To control a matrix, you connect both its rows and columns to your microcontroller. The columns are connected to the LEDs cathodes (see Figure 1), so a column needs to be high for any of the LEDs in that column to turn on. The rows are connected to the LEDs anodes, so the row needs to be low for an individual LED to turn on. If the row and the column are both high or both low, no voltage flows through the LED and it doesn’t turn on.
Deleted line 215:
May 02, 2012, at 04:04 PM by Scott Fitzgerald -
Changed line 191 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/7.Display/RowColumnScanning/RowColumnScanning.ino lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/07.Display/RowColumnScanning/RowColumnScanning.ino lang=arduino tabwidth=4:)
November 16, 2011, at 04:20 AM by Scott Fitzgerald -
Changed line 191 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/7.Display/RowColumnScanning/RowColumnScanning.pde lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/7.Display/RowColumnScanning/RowColumnScanning.ino lang=arduino tabwidth=4:)
September 24, 2010, at 05:54 AM by Tom Igoe -
Changed lines 207-208 from:
* [[LED Bar Graph]]: how to make an LED bar graph.
to:
* LED [[Bar Graph]]: how to make an LED bar graph.
September 23, 2010, at 10:43 PM by Christian Cerrito -
Changed lines 3-4 from:
!! Row-columm Scanning to control an 8x8 LED Matrix
to:
!!! Row-columm Scanning to control an 8x8 LED Matrix
September 19, 2010, at 10:01 PM by Christian Cerrito -
Added line 210:
September 19, 2010, at 09:56 PM by Christian Cerrito -
Changed lines 207-208 from:
* [[Row Column Scanning]] - how to control an 8x8 matrix of LEDs.
to:
* [[LED Bar Graph]]: how to make an LED bar graph.
September 19, 2010, at 09:53 PM by Christian Cerrito -
Changed line 203 from:
* [[FunctionDeclaration | Writing Functions]] - create modular pieces of code to perform a defined task.
to:
* [[Reference/FunctionDeclaration | Writing Functions]] - create modular pieces of code to perform a defined task.
Added lines 213-215:


September 19, 2010, at 09:52 PM by Christian Cerrito -
Changed lines 195-208 from:
to:
!!!See Also:

* [[Reference/PinMode | @@pinMode()@@ ]]
* [[Reference/For | @@for()@@]]
* [[Reference/DigitalWrite | @@digitalWrite()@@]]
* [[Reference/If | @@if()@@]]
* [[Reference/Map | @@map()@@]]

* [[FunctionDeclaration | Writing Functions]] - create modular pieces of code to perform a defined task.
* [[ForLoop | For Loop]] - control multiple LEDs with a For Loop.
* [[Array]] - a variation on the For Loop example that demonstrates how to use an array.
* [[Tutorial/IfStatement | If Statement]] - how to use an if statement to change output conditions based on changing input conditions.
* [[Row Column Scanning]] - how to control an 8x8 matrix of LEDs.
September 19, 2010, at 09:47 PM by Christian Cerrito -
Changed lines 170-173 from:
the 16 pins of the matrix are hooked up to 16 pins of the Arduino. Four of the analog pins are used as digital inputs 16 through 19. The order of the pins is assigned in two arrays in the code.

Two potentiometers control the movement of a lit LED in the matrix.
to:
The 16 pins of the matrix are hooked up to 16 pins of the Arduino. Four of the analog pins are used as digital inputs 16 through 19. The order of the pins is assigned in two arrays in the code.

Two potentiometers, connected to analog pins 0 and 1, control the movement of a lit LED in the matrix.
September 19, 2010, at 09:46 PM by Christian Cerrito -
Added lines 160-167:

!!!Hardware Required
* Arduino Board
* (1) 8 x 8 LED Matrix
* (2) potentiometers
* hook-up wire
* breadboard
September 16, 2010, at 10:20 PM by Tom Igoe -
Changed line 183 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/Display/RowColumnScanning/RowColumnScanning.pde lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/7.Display/RowColumnScanning/RowColumnScanning.pde lang=arduino tabwidth=4:)
February 24, 2010, at 04:33 AM by Tom Igoe -
Changed lines 183-214 from:
%color=#7e7e7e%/*
%color=#7e7e7e% Row-Column Scanning an 8x8 LED matrix with X-Y input
%color=#7e7e7e%
%color=#7e7e7e% This example controls an 8x8 LED matrix using two analog inputs
%color=#7e7e7e%
%color=#7e7e7e% created 27 May 2009
%color=#7e7e7e% modified 29 Jun 2009
%color=#7e7e7e% by Tom Igoe
%color=#7e7e7e%
%color=#7e7e7e% This example works for the Lumex LDM-24488NI Matrix. See
%color=#7e7e7e% http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf
%color=#7e7e7e% for the pin connections
%color=#7e7e7e%
%color=#7e7e7e% For other LED cathode column matrixes, you should only need to change
%color=#7e7e7e% the pin numbers in the row[] and column[] arrays
%color=#7e7e7e%
%color=#7e7e7e% rows are the anodes
%color=#7e7e7e% cols are the cathodes
%color=#7e7e7e% ---------
%color=#7e7e7e%
%color=#7e7e7e% Pin numbers:
%color=#7e7e7e% Matrix:
%color=#7e7e7e% * Digital pins 2 through 13,
%color=#7e7e7e% * analog pins 2 through 5 used as digital 16 through 19
%color=#7e7e7e% Potentiometers:
%color=#7e7e7e% * center pins are attached to analog pins 0 and 1, respectively
%color=#7e7e7e% * side pins attached to +5V and ground, respectively.
%color=#7e7e7e%
%color=#7e7e7e% http://www.arduino.cc/en/Tutorial/RowColumnScanning
%color=#7e7e7e%
%color=#7e7e7e% see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
%color=#7e7e7e% */
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/Display/RowColumnScanning/RowColumnScanning.pde lang=arduino tabwidth=4:)
Deleted lines 184-263:

%color=#7e7e7e%// 2-dimensional array of row pin numbers:
const %color=#cc6600%int%% row[8] = {
2,7,19,5,13,18,12,16 };

%color=#7e7e7e%// 2-dimensional array of column pin numbers:
const %color=#cc6600%int%% col[8] = {
6,11,10,3,17,4,8,9 };

%color=#7e7e7e%// 2-dimensional array of pixels:
%color=#cc6600%int%% pixels[8][8];

%color=#7e7e7e%// cursor position:
%color=#cc6600%int%% x = 5;
%color=#cc6600%int%% y = 5;

%color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
%color=#cc6600%Serial%%.%color=#cc6600%begin%%(9600);
%color=#7e7e7e%// initialize the I/O pins as outputs:

%color=#7e7e7e%// iterate over the pins:
%color=#cc6600%for%% (%color=#cc6600%int%% thisPin = 0; thisPin < 8; thisPin++) {
%color=#7e7e7e%// initialize the output pins:
%color=#cc6600%pinMode%%(col[thisPin], %color=#006699%OUTPUT%%);
%color=#cc6600%pinMode%%(row[thisPin], %color=#006699%OUTPUT%%);
%color=#7e7e7e%// take the col pins (i.e. the cathodes) high to ensure that
%color=#7e7e7e%// the LEDS are off:
%color=#cc6600%digitalWrite%%(col[thisPin], %color=#006699%HIGH%%);
}

%color=#7e7e7e%// initialize the pixel matrix:
%color=#cc6600%for%% (%color=#cc6600%int%% x = 0; x < 8; x++) {
%color=#cc6600%for%% (%color=#cc6600%int%% y = 0; y < 8; y++) {
pixels[x][y] = %color=#006699%HIGH%%;
}
}
}

%color=#cc6600%void%% %color=#cc6600%'''loop'''%%() {
%color=#7e7e7e%// read input:
readSensors();

%color=#7e7e7e%// draw the screen:
refreshScreen();
}

%color=#cc6600%void%% readSensors() {
%color=#7e7e7e%// turn off the last position:
pixels[x][y] = %color=#006699%HIGH%%;
%color=#7e7e7e%// read the sensors for X and Y values:
x = 7 - %color=#cc6600%map%%(%color=#cc6600%analogRead%%(0), 0, 1023, 0, 7);
y = %color=#cc6600%map%%(%color=#cc6600%analogRead%%(1), 0, 1023, 0, 7);
%color=#7e7e7e%// set the new pixel position low so that the LED will turn on
%color=#7e7e7e%// in the next screen refresh:
pixels[x][y] = %color=#006699%LOW%%;

}

%color=#cc6600%void%% refreshScreen() {
%color=#7e7e7e%// iterate over the rows (anodes):
%color=#cc6600%for%% (%color=#cc6600%int%% thisRow = 0; thisRow < 8; thisRow++) {
%color=#7e7e7e%// take the row pin (anode) high:
%color=#cc6600%digitalWrite%%(row[thisRow], %color=#006699%HIGH%%);
%color=#7e7e7e%// iterate over the cols (cathodes):
%color=#cc6600%for%% (%color=#cc6600%int%% thisCol = 0; thisCol < 8; thisCol++) {
%color=#7e7e7e%// get the state of the current pixel;
%color=#cc6600%int%% thisPixel = pixels[thisRow][thisCol];
%color=#7e7e7e%// when the row is HIGH and the col is LOW,
%color=#7e7e7e%// the LED where they meet turns on:
%color=#cc6600%digitalWrite%%(col[thisCol], thisPixel);
%color=#7e7e7e%// turn the pixel off:
%color=#cc6600%if%% (thisPixel == %color=#006699%LOW%%) {
%color=#cc6600%digitalWrite%%(col[thisCol], %color=#006699%HIGH%%);
}
}
%color=#7e7e7e%// take the row pin low to turn off the whole row:
%color=#cc6600%digitalWrite%%(row[thisRow], %color=#006699%LOW%%);
}
}
November 26, 2009, at 06:17 AM by David A. Mellis -
Changed line 219 from:
2,7,19,5,18,12,16 };
to:
2,7,19,5,13,18,12,16 };
August 27, 2009, at 08:57 PM by Tom Igoe -
Added lines 170-172:
[-image developed using [[http://www.fritzing.org |Fritzing]]. For more circuit examples, see the [[http://fritzing.org/projects/|Fritzing project page]] -]

July 05, 2009, at 07:50 PM by Tom Igoe -
Changed lines 177-179 from:
[@
/*
Row-Column Scanning an 8x8 LED matrix with X-Y input
to:

(:div class=code :)

%color=#7e7e7e%/*
%color=#7e7e7e% Row-Column Scanning an 8x8 LED matrix with X-Y input
%color=#7e7e7e%
%color=#7e7e7e% This example controls an 8x8 LED matrix using two analog inputs
%color=#7e7e7e%
%color=#7e7e7e% created 27 May 2009
%color=#7e7e7e% modified 29 Jun 2009
%color=#7e7e7e% by Tom Igoe
%color=#7e7e7e%
%color=#7e7e7e% This example works for the Lumex LDM-24488NI Matrix. See
%color=#7e7e7e% http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf
%color=#7e7e7e% for the pin connections
%color=#7e7e7e%
%color=#7e7e7e% For other LED cathode column matrixes, you should only need to change
%color=#7e7e7e% the pin numbers in the row[] and column[] arrays
%color=#7e7e7e%
%color=#7e7e7e% rows are the anodes
%color=#7e7e7e% cols are the cathodes
%color=#7e7e7e% ---------
%color=#7e7e7e%
%color=#7e7e7e% Pin numbers:
%color=#7e7e7e% Matrix:
%color=#7e7e7e% * Digital pins 2 through 13,
%color=#7e7e7e% * analog pins 2 through 5 used as digital 16 through 19
%color=#7e7e7e% Potentiometers:
%color=#7e7e7e% * center pins are attached to analog pins 0 and 1, respectively
%color=#7e7e7e% * side pins attached to +5V and ground, respectively.
%color=#7e7e7e%
%color=#7e7e7e% http://www.arduino.cc/en/Tutorial/RowColumnScanning
%color=#7e7e7e%
%color=#7e7e7e% see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
%color=#7e7e7e% */
Deleted line 212:
This example controls an 8x8 LED matrix using two analog inputs
Changed lines 214-216 from:
created 27 May 2009
modified 29 Jun 2009
by Tom Igoe
to:
%color=#7e7e7e%// 2-dimensional array of row pin numbers:
const %color=#cc6600%int%% row[8] = {
2,7,19,5,18,12,16 };
Changed lines 218-220 from:
This example works for the Lumex LDM-24488NI Matrix. See
http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf
for the pin connections
to:
%color=#7e7e7e%// 2-dimensional array of column pin numbers:
const %color=#cc6600%int%% col[8] = {
6,11,10,3,17,4,8,9 };
Changed lines 222-223 from:
For other LED cathode column matrixes, you should only need to change
the pin numbers in the row[] and column[] arrays
to:
%color=#7e7e7e%// 2-dimensional array of pixels:
%color=#cc6600%int%% pixels[8][8];
Changed lines 225-227 from:
rows are the anodes
cols are the cathodes
---------
to:
%color=#7e7e7e%// cursor position:
%color=#cc6600%int%% x = 5;
%color=#cc6600%int%% y = 5;
Changed lines 229-235 from:
Pin numbers:
Matrix:
* Digital pins 2 through 13,
* analog pins 2 through 5 used as digital 16 through 19
Potentiometers:
* center pins are attached to analog pins 0 and 1, respectively
* side pins attached to +5V and ground, respectively.
to:
%color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
%color=#cc6600%Serial%%.%color=#cc6600%begin%%(9600);
%color=#7e7e7e%// initialize the I/O pins as outputs:
Changed lines 233-241 from:
http://www.arduino.cc/en/Tutorial/RowColumnScanning
to:
%color=#7e7e7e%// iterate over the pins:
%color=#cc6600%for%% (%color=#cc6600%int%% thisPin = 0; thisPin < 8; thisPin++) {
%color=#7e7e7e%// initialize the output pins:
%color=#cc6600%pinMode%%(col[thisPin], %color=#006699%OUTPUT%%);
%color=#cc6600%pinMode%%(row[thisPin], %color=#006699%OUTPUT%%);
%color=#7e7e7e%// take the col pins (i.e. the cathodes) high to ensure that
%color=#7e7e7e%// the LEDS are off:
%color=#cc6600%digitalWrite%%(col[thisPin], %color=#006699%HIGH%%);
}
Changed lines 243-325 from:
see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
*/


// 2-dimensional array of row pin numbers:
const int row[8] = {
2,7,19,5,18,12,16 };

// 2-dimensional array of column pin numbers:
const int col[8] = {
6,11,10,3,17,4,8,9 };

// 2-dimensional array of pixels:
int pixels[8][8];

// cursor position:
int x = 5;
int y = 5;

void setup() {
Serial.begin(9600);
// initialize the I/O pins as outputs:

// iterate over the pins:
for (int thisPin = 0; thisPin < 8; thisPin++) {
// initialize the output pins:
pinMode(col[thisPin], OUTPUT);
pinMode(row[thisPin], OUTPUT);
// take the col pins (i.e. the cathodes) high to ensure that
// the LEDS are off:
digitalWrite(col[thisPin], HIGH);
}

// initialize the pixel matrix:
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
pixels[x][y] = HIGH;
}
}
}

void loop() {
// read input:
readSensors();

// draw the screen:
refreshScreen();
}

void readSensors() {
// turn off the last position:
pixels[x][y] = HIGH;
// read the sensors for X and Y values:
x = 7 - map(analogRead(0), 0, 1023, 0, 7);
y = map(analogRead(1), 0, 1023, 0, 7);
// set the new pixel position low so that the LED will turn on
// in the next screen refresh:
pixels[x][y] = LOW;

}

void refreshScreen() {
// iterate over the rows (anodes):
for (int thisRow = 0; thisRow < 8; thisRow++) {
// take the row pin (anode) high:
digitalWrite(row[thisRow], HIGH);
// iterate over the cols (cathodes):
for (int thisCol = 0; thisCol < 8; thisCol++) {
// get the state of the current pixel;
int thisPixel = pixels[thisRow][thisCol];
// when the row is HIGH and the col is LOW,
// the LED where they meet turns on:
digitalWrite(col[thisCol], thisPixel);
// turn the pixel off:
if (thisPixel == LOW) {
digitalWrite(col[thisCol], HIGH);
}
}
// take the row pin low to turn off the whole row:
digitalWrite(row[thisRow], LOW);
}
}
@]
to:
%color=#7e7e7e%// initialize the pixel matrix:
%color=#cc6600%for%% (%color=#cc6600%int%% x = 0; x < 8; x++) {
%color=#cc6600%for%% (%color=#cc6600%int%% y = 0; y < 8; y++) {
pixels[x][y] = %color=#006699%HIGH%%;
}
}
}

%color=#cc6600%void%% %color=#cc6600%'''loop'''%%() {
%color=#7e7e7e%// read input:
readSensors();

%color=#7e7e7e%// draw the screen:
refreshScreen();
}

%color=#cc6600%void%% readSensors() {
%color=#7e7e7e%// turn off the last position:
pixels[x][y] = %color=#006699%HIGH%%;
%color=#7e7e7e%// read the sensors for X and Y values:
x = 7 - %color=#cc6600%map%%(%color=#cc6600%analogRead%%(0), 0, 1023, 0, 7);
y = %color=#cc6600%map%%(%color=#cc6600%analogRead%%(1), 0, 1023, 0, 7);
%color=#7e7e7e%// set the new pixel position low so that the LED will turn on
%color=#7e7e7e%// in the next screen refresh:
pixels[x][y] = %color=#006699%LOW%%;

}

%color=#cc6600%void%% refreshScreen() {
%color=#7e7e7e%// iterate over the rows (anodes):
%color=#cc6600%for%% (%color=#cc6600%int%% thisRow = 0; thisRow < 8; thisRow++) {
%color=#7e7e7e%// take the row pin (anode) high:
%color=#cc6600%digitalWrite%%(row[thisRow], %color=#006699%HIGH%%);
%color=#7e7e7e%// iterate over the cols (cathodes):
%color=#cc6600%for%% (%color=#cc6600%int%% thisCol = 0; thisCol < 8; thisCol++) {
%color=#7e7e7e%// get the state of the current pixel;
%color=#cc6600%int%% thisPixel = pixels[thisRow][thisCol];
%color=#7e7e7e%// when the row is HIGH and the col is LOW,
%color=#7e7e7e%// the LED where they meet turns on:
%color=#cc6600%digitalWrite%%(col[thisCol], thisPixel);
%color=#7e7e7e%// turn the pixel off:
%color=#cc6600%if%% (thisPixel == %color=#006699%LOW%%) {
%color=#cc6600%digitalWrite%%(col[thisCol], %color=#006699%HIGH%%);
}
}
%color=#7e7e7e%// take the row pin low to turn off the whole row:
%color=#cc6600%digitalWrite%%(row[thisRow], %color=#006699%LOW%%);
}
}

(:divend:)

June 30, 2009, at 05:13 PM by Tom Igoe -
Changed line 184 from:
modified 26 Jun 2009
to:
modified 29 Jun 2009
Changed lines 189-196 from:
for the pin connections.

For other LED cathode column matrixes, you should only need to change
the pin numbers in the row[] and column[] arrays

rows are the anodes
cols are the cathodes
---------
to:
for the pin connections
Added lines 191-197:
For other LED cathode column matrixes, you should only need to change
the pin numbers in the row[] and column[] arrays

rows are the anodes
cols are the cathodes
---------
Changed lines 202-203 from:
Accelerometer:
* X and Y axes attached to analog in 0 and 1
to:
Potentiometers:
* center pins are attached to analog pins 0 and 1, respectively
* side pins attached to +5V and ground, respectively.
Changed lines 206-208 from:
http://www.arduino.cc/en/Tutorial/RowColumnScanning

see http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
to:
http://www.arduino.cc/en/Tutorial/RowColumnScanning

see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
Changed lines 211-215 from:
// max and min values from the accelerometer,
// found by experiment:
const int sensorMin = 380;
const int sensorMax = 620;
to:
Changed lines 214-215 from:
2,7,19,5,18,12,16 };
to:
2,7,19,5,18,12,16 };
Changed lines 261-262 from:
x = 7 - map(analogRead(0), sensorMin, sensorMax, 0, 7);
y = map(analogRead(1), sensorMin, sensorMax, 0, 7);
to:
x = 7 - map(analogRead(0), 0, 1023, 0, 7);
y = map(analogRead(1), 0, 1023, 0, 7);
// set the new pixel position low so that the LED will turn on
// in the next screen refresh:
June 30, 2009, at 05:11 PM by Tom Igoe -
Changed lines 172-173 from:
[-click the image to enlarge-]
to:
[-click the image to enlarge-].
June 29, 2009, at 06:00 PM by Tom Igoe -
Added lines 162-165:
the 16 pins of the matrix are hooked up to 16 pins of the Arduino. Four of the analog pins are used as digital inputs 16 through 19. The order of the pins is assigned in two arrays in the code.

Two potentiometers control the movement of a lit LED in the matrix.
June 29, 2009, at 05:53 PM by Tom Igoe -
Added lines 16-17:
Although there are pre-made LED matrices, you can also make your own matrix from 64 LEDs, using the schematic as shown above.
Deleted lines 21-22:

June 29, 2009, at 05:51 PM by Tom Igoe -
Changed lines 5-6 from:
LED displays are often packaged as matrixes of LEDs arranged in rows of common anodes and columns of common cathodes, or the reverse. Here's a typical example, and its schematic:
to:
LED displays are often packaged as matrixes of LEDs arranged in rows of common anodes and columns of common cathodes, or the reverse. Here's a [[http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf|typical example]], and its schematic:
June 29, 2009, at 05:51 PM by Tom Igoe -
Changed lines 175-176 from:
Row-Column Scanning an 8x8 LED matrix with accelerometer
for Arduino
to:
Row-Column Scanning an 8x8 LED matrix with X-Y input
Changed lines 177-178 from:
This example controls an 8x8 LED matrix using two inputs
from an accelerometer.
to:
This example controls an 8x8 LED matrix using two analog inputs
Changed lines 183-186 from:
This example works for the Fairchild GMA2288C matrix. See
http://sigma.octopart.com/125394/datasheet/Fairchild-GMA2288C.pdf
for the pin connections
to:
This example works for the Lumex LDM-24488NI Matrix. See
http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf
for the pin connections.

For other LED cathode column matrixes, you should only need to change
the pin numbers in the row[] and column[] arrays
Added line 203:
see http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
Changed lines 213-214 from:
9,8,7,6,16,17,18,19 };
to:
2,7,19,5,18,12,16 };
Changed lines 217-218 from:
13,12,11,10,5,4,3,2 };
to:
6,11,10,3,17,4,8,9 };
Deleted line 253:
Deleted line 285:
Deleted line 286:
June 29, 2009, at 05:47 PM by Tom Igoe -
June 29, 2009, at 05:44 PM by Tom Igoe -
Added line 21:
Deleted line 38:
Deleted line 46:
Deleted line 54:
Deleted line 62:
Deleted lines 70-71:

Deleted lines 78-79:

Deleted lines 86-87:

Deleted lines 94-95:

Deleted lines 102-103:

Deleted lines 110-111:

Deleted lines 118-119:

Deleted lines 126-127:

Deleted lines 134-135:

Deleted line 159:
June 29, 2009, at 05:43 PM by Tom Igoe -
June 29, 2009, at 05:42 PM by Tom Igoe -
Added line 20:
Changed line 22 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 30 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 39 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 48 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 57 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 66 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 76 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 86 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 96 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 106 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 116 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 126 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 136 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 146 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 156 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 164 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
Changed line 172 from:
(:cell align=centernr align=center:)
to:
(:cellnr align=center:)
June 29, 2009, at 05:41 PM by Tom Igoe -
Changed line 21 from:
(:cellnr align=center:)
to:
(:cell align=centernr align=center:)
Changed line 23 from:
(:cell:)
to:
(:cell align=center:)
Changed line 25 from:
(:cell:)
to:
(:cell align=center:)
Changed line 27 from:
(:cell:)
to:
(:cell align=center:)
Changed line 29 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 31 from:
(:cell:)
to:
(:cell align=center:)
Changed line 33 from:
(:cell:)
to:
(:cell align=center:)
Changed line 35 from:
(:cell:)
to:
(:cell align=center:)
Changed line 38 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 40 from:
(:cell:)
to:
(:cell align=center:)
Changed line 42 from:
(:cell:)
to:
(:cell align=center:)
Changed line 44 from:
(:cell:)
to:
(:cell align=center:)
Changed line 47 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 49 from:
(:cell:)
to:
(:cell align=center:)
Changed line 51 from:
(:cell:)
to:
(:cell align=center:)
Changed line 53 from:
(:cell:)
to:
(:cell align=center:)
Changed line 56 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 58 from:
(:cell:)
to:
(:cell align=center:)
Changed line 60 from:
(:cell:)
to:
(:cell align=center:)
Changed line 62 from:
(:cell:)
to:
(:cell align=center:)
Changed line 65 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 67 from:
(:cell:)
to:
(:cell align=center:)
Changed line 69 from:
(:cell:)
to:
(:cell align=center:)
Changed line 71 from:
(:cell:)
to:
(:cell align=center:)
Changed line 75 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 77 from:
(:cell:)
to:
(:cell align=center:)
Changed line 79 from:
(:cell:)
to:
(:cell align=center:)
Changed line 81 from:
(:cell:)
to:
(:cell align=center:)
Changed line 85 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 87 from:
(:cell:)
to:
(:cell align=center:)
Changed line 89 from:
(:cell:)
to:
(:cell align=center:)
Changed line 91 from:
(:cell:)
to:
(:cell align=center:)
Changed line 95 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 97 from:
(:cell:)
to:
(:cell align=center:)
Changed line 99 from:
(:cell:)
to:
(:cell align=center:)
Changed line 101 from:
(:cell:)
to:
(:cell align=center:)
Changed line 105 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 107 from:
(:cell:)
to:
(:cell align=center:)
Changed line 109 from:
(:cell:)
to:
(:cell align=center:)
Changed line 111 from:
(:cell:)
to:
(:cell align=center:)
Changed line 115 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 117 from:
(:cell:)
to:
(:cell align=center:)
Changed line 119 from:
(:cell:)
to:
(:cell align=center:)
Changed line 121 from:
(:cell:)
to:
(:cell align=center:)
Changed line 125 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 127 from:
(:cell:)
to:
(:cell align=center:)
Changed line 129 from:
(:cell:)
to:
(:cell align=center:)
Changed line 131 from:
(:cell:)
to:
(:cell align=center:)
Changed line 135 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 137 from:
(:cell:)
to:
(:cell align=center:)
Changed line 139 from:
(:cell:)
to:
(:cell align=center:)
Changed line 141 from:
(:cell:)
to:
(:cell align=center:)
Changed line 145 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 147 from:
(:cell:)
to:
(:cell align=center:)
Changed line 149 from:
(:cell:)
to:
(:cell align=center:)
Changed line 151 from:
(:cell:)
to:
(:cell align=center:)
Changed line 155 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 157 from:
(:cell:)
to:
(:cell align=center:)
Changed line 159 from:
(:cell:)
to:
(:cell align=center:)
Changed line 161 from:
(:cell:)
to:
(:cell align=center:)
Changed line 163 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 165 from:
(:cell:)
to:
(:cell align=center:)
Changed line 167 from:
(:cell:)
to:
(:cell align=center:)
Changed line 169 from:
(:cell:)
to:
(:cell align=center:)
Changed line 171 from:
(:cellnr:)
to:
(:cell align=centernr align=center:)
Changed line 173 from:
(:cell:)
to:
(:cell align=center:)
Changed line 175 from:
(:cell:)
to:
(:cell align=center:)
Changed line 177 from:
(:cell:)
to:
(:cell align=center:)
June 29, 2009, at 05:40 PM by Tom Igoe -
Changed line 21 from:
(:cellnr:)
to:
(:cellnr align=center:)
June 29, 2009, at 05:39 PM by Tom Igoe -
Changed line 20 from:
(:table border=1 font size=bigger:)
to:
(:table border=1 align=center summary="Mapping: LED Matrix pin numbers to rows and columns to Arduino pin numbers":)
June 29, 2009, at 05:37 PM by Tom Igoe -
Changed line 20 from:
(:table border=1 font=+1:)
to:
(:table border=1 font size=bigger:)
June 29, 2009, at 05:37 PM by Tom Igoe -
Changed line 20 from:
(:table border=1:)
to:
(:table border=1 font=+1:)
June 29, 2009, at 05:36 PM by Tom Igoe -
Changed lines 18-19 from:
Here's a matrix of the pin connections
to:
Here's a matrix of the pin connections, based on the diagram above:
Changed line 24 from:
Row'''
to:
'''Row'''
Changed line 26 from:
Column'''
to:
'''Column'''
Changed line 28 from:
Arduino pin number'''
to:
'''Arduino pin number'''
Changed line 106 from:
X
to:
9
Changed line 108 from:
X
to:
1
Changed line 110 from:
X
to:
-
Changed lines 112-114 from:
X

to:
2

Changed line 116 from:
X
to:
10
Changed line 118 from:
X
to:
-
Changed line 120 from:
X
to:
4
Changed lines 122-124 from:
X

to:
3

Changed line 126 from:
X
to:
11
Changed line 128 from:
X
to:
-
Changed line 130 from:
X
to:
6
Changed lines 132-134 from:
X

to:
4

Changed line 136 from:
X
to:
12
Changed line 138 from:
X
to:
4
Changed line 140 from:
X
to:
-
Changed lines 142-144 from:
X

to:
5

Changed line 146 from:
X
to:
13
Changed line 148 from:
X
to:
-
Changed line 150 from:
X
to:
1
Changed lines 152-154 from:
X

to:
6

Changed line 156 from:
X
to:
14
Changed line 158 from:
X
to:
2
Changed line 160 from:
X
to:
-
Changed lines 162-164 from:
X

to:
7
Changed line 164 from:
X
to:
15
Changed line 166 from:
X
to:
-
Changed line 168 from:
X
to:
7
Changed lines 170-172 from:
X

to:
8
Changed line 172 from:
X
to:
16
Changed line 174 from:
X
to:
-
Changed line 176 from:
X
to:
8
Changed lines 178-180 from:
X

to:
9
June 29, 2009, at 05:33 PM by Tom Igoe -
Changed line 22 from:
'''Matrix pin no.
to:
'''Matrix pin no.'''
Changed line 24 from:
Row
to:
Row'''
Changed line 26 from:
Column
to:
Column'''
Changed lines 36-37 from:
X
to:
13
Changed line 39 from:
-
to:
2
Added lines 41-42:
7
(:cell:)
Added lines 45-49:
12

(:cellnr:)
3
(:cell:)
Added lines 52-58:
2
(:cell:)
11

(:cellnr:)
4
(:cell:)
Added lines 60-184:
(:cell:)
3
(:cell:)
10

(:cellnr:)
5
(:cell:)
8
(:cell:)
-
(:cell:)
16 (analog pin 2)


(:cellnr:)
6
(:cell:)
-
(:cell:)
5
(:cell:)
17 (analog pin 3)


(:cellnr:)
7
(:cell:)
6
(:cell:)
-
(:cell:)
18 (analog pin 4)


(:cellnr:)
8
(:cell:)
3
(:cell:)
-
(:cell:)
19 (analog pin 5)


(:cellnr:)
X
(:cell:)
X
(:cell:)
X
(:cell:)
X


(:cellnr:)
X
(:cell:)
X
(:cell:)
X
(:cell:)
X


(:cellnr:)
X
(:cell:)
X
(:cell:)
X
(:cell:)
X


(:cellnr:)
X
(:cell:)
X
(:cell:)
X
(:cell:)
X


(:cellnr:)
X
(:cell:)
X
(:cell:)
X
(:cell:)
X


(:cellnr:)
X
(:cell:)
X
(:cell:)
X
(:cell:)
X


(:cellnr:)
X
(:cell:)
X
(:cell:)
X
(:cell:)
X


(:cellnr:)
X
(:cell:)
X
(:cell:)
X
(:cell:)
X

June 29, 2009, at 05:28 PM by Tom Igoe -
Changed line 22 from:
Matrix pin no.
to:
'''Matrix pin no.
Changed line 28 from:
Arduino pin number
to:
Arduino pin number'''
June 29, 2009, at 05:27 PM by Tom Igoe -
Changed line 21 from:
(cellnr:)
to:
(:cellnr:)
June 29, 2009, at 05:26 PM by Tom Igoe -
Changed lines 21-22 from:
(cellnr:)Matrix pin no.
to:
(cellnr:)
Matrix pin no.
Deleted line 28:
Added line 38:
-
Added line 40:
-
Added line 42:
-
Changed line 44 from:
to:
-
June 29, 2009, at 05:26 PM by Tom Igoe -
Added lines 18-43:
Here's a matrix of the pin connections

(:table border=1:)
(cellnr:)Matrix pin no.
(:cell:)
Row
(:cell:)
Column
(:cell:)
Arduino pin number

(:cellnr:)
1
(:cell:)
5
(:cell:)
-
(:cell:)
X
(:cellnr:)
(:cell:)
(:cell:)
(:cell:)

(:tableend:)
June 26, 2009, at 10:34 PM by Tom Igoe -
Changed lines 7-13 from:

%width=300px%[[Attach:LEDmatrix_img.jpg | Attach:LEDmatrix_img.jpg]]


%width=300px%[[Attach:LEDmatrix_schem.png | Attach:LEDmatrix_schem.png]]

to:
Attach:LEDmatrix_img.jpg


Attach:LEDmatrix_schem.png
June 26, 2009, at 10:28 PM by Tom Igoe -
June 26, 2009, at 10:26 PM by Tom Igoe -
Added lines 1-152:
''Examples > Display''

!! Row-columm Scanning to control an 8x8 LED Matrix

LED displays are often packaged as matrixes of LEDs arranged in rows of common anodes and columns of common cathodes, or the reverse. Here's a typical example, and its schematic:


%width=300px%[[Attach:LEDmatrix_img.jpg | Attach:LEDmatrix_img.jpg]]


%width=300px%[[Attach:LEDmatrix_schem.png | Attach:LEDmatrix_schem.png]]


These can be very useful displays. To control a matrix, you connect both its rows and columns to your microcontroller. The columns are connected to the LEDs anodes (see Figure 1), so a column needs to be high for any of the LEDs in that column to turn on. The rows are connected to the LEDs cathodes, so the row needs to be low for an individual LED to turn on. If the row and the column are both high or both low, no voltage flows through the LED and it doesn’t turn on.

To control an individual LED, you set its column high and its row low. To control multiple LEDs in a row, you set the rows high, then take the column high, then set the lows row or high as appropriate; a low row will turn the corresponding LED on, and a high row will turn it off.

It doesn’t matter which pins of the microcontroller you connect the rows and columns to, because you can assign things in software. Connected the pins in a way that makes wiring easiest. A typical layout is shown below.

!!!Circuit

[-click the image to enlarge-]

%width=400px%[[Attach:rowColScan_bb.png | Attach:rowColScan_bb.png]]

'''Schematic:'''

[-click the image to enlarge-]

%width=400px%[[Attach:rowColScan_schem.png | Attach:rowColScan_schem.png]]

!!!Code
[@
/*
Row-Column Scanning an 8x8 LED matrix with accelerometer
for Arduino

This example controls an 8x8 LED matrix using two inputs
from an accelerometer.

created 27 May 2009
modified 26 Jun 2009
by Tom Igoe

This example works for the Fairchild GMA2288C matrix. See
http://sigma.octopart.com/125394/datasheet/Fairchild-GMA2288C.pdf
for the pin connections

rows are the anodes
cols are the cathodes
---------

Pin numbers:
Matrix:
* Digital pins 2 through 13,
* analog pins 2 through 5 used as digital 16 through 19
Accelerometer:
* X and Y axes attached to analog in 0 and 1

http://www.arduino.cc/en/Tutorial/RowColumnScanning

*/

// max and min values from the accelerometer,
// found by experiment:
const int sensorMin = 380;
const int sensorMax = 620;

// 2-dimensional array of row pin numbers:
const int row[8] = {
9,8,7,6,16,17,18,19 };

// 2-dimensional array of column pin numbers:
const int col[8] = {
13,12,11,10,5,4,3,2 };

// 2-dimensional array of pixels:
int pixels[8][8];

// cursor position:
int x = 5;
int y = 5;

void setup() {
Serial.begin(9600);
// initialize the I/O pins as outputs:

// iterate over the pins:
for (int thisPin = 0; thisPin < 8; thisPin++) {
// initialize the output pins:
pinMode(col[thisPin], OUTPUT);
pinMode(row[thisPin], OUTPUT);
// take the col pins (i.e. the cathodes) high to ensure that
// the LEDS are off:
digitalWrite(col[thisPin], HIGH);
}

// initialize the pixel matrix:
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
pixels[x][y] = HIGH;
}
}
}

void loop() {
// read input:
readSensors();

// draw the screen:
refreshScreen();

}

void readSensors() {
// turn off the last position:
pixels[x][y] = HIGH;
// read the sensors for X and Y values:
x = 7 - map(analogRead(0), sensorMin, sensorMax, 0, 7);
y = map(analogRead(1), sensorMin, sensorMax, 0, 7);
pixels[x][y] = LOW;

}

void refreshScreen() {
// iterate over the rows (anodes):
for (int thisRow = 0; thisRow < 8; thisRow++) {
// take the row pin (anode) high:
digitalWrite(row[thisRow], HIGH);
// iterate over the cols (cathodes):
for (int thisCol = 0; thisCol < 8; thisCol++) {
// get the state of the current pixel;
int thisPixel = pixels[thisRow][thisCol];
// when the row is HIGH and the col is LOW,
// the LED where they meet turns on:
digitalWrite(col[thisCol], thisPixel);
// turn the pixel off:
if (thisPixel == LOW) {
digitalWrite(col[thisCol], HIGH);
}
}
// take the row pin low to turn off the whole row:
digitalWrite(row[thisRow], LOW);
}

}

@]
There is [[http://www.arduino.cc/playground/Main/DirectDriveLEDMatrix | a more complex example in the Arduino playground]]. Other examples can be found [[http://www.tigoe.net/pcomp/code/ |on Tom Igoe's blog]]:
* [[http://www.tigoe.net/pcomp/code/category/arduinowiring/514 |Tom's original version of this tutorial]]
* [[http://www.tigoe.net/pcomp/code/category/arduinowiring/424| Two matrixes on an Arduino Mega]]
* [[http://www.tigoe.net/pcomp/code/category/Processing/454 | Two-Matrix Pong]]

Share