Show minor edits - Show changes to markup
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/7.Display/RowColumnScanning/RowColumnScanning.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/07.Display/RowColumnScanning/RowColumnScanning.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/7.Display/RowColumnScanning/RowColumnScanning.pde lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/7.Display/RowColumnScanning/RowColumnScanning.ino lang=arduino tabwidth=4:)
pinMode()
for()
digitalWrite()
if()
map()
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.
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.
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/Display/RowColumnScanning/RowColumnScanning.pde lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/7.Display/RowColumnScanning/RowColumnScanning.pde lang=arduino tabwidth=4:)
/* Row-Column Scanning an 8x8 LED matrix with X-Y input This example controls an 8x8 LED matrix using two analog inputs created 27 May 2009 modified 29 Jun 2009 by Tom Igoe 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 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 Potentiometers: * center pins are attached to analog pins 0 and 1, respectively * side pins attached to +5V and ground, respectively. http://www.arduino.cc/en/Tutorial/RowColumnScanning see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more */
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/Display/RowColumnScanning/RowColumnScanning.pde lang=arduino tabwidth=4:)
// 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 };
// 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); } }
2,7,19,5,18,12,16 };
2,7,19,5,13,18,12,16 };
image developed using Fritzing. For more circuit examples, see the Fritzing project page
[@ /*
Row-Column Scanning an 8x8 LED matrix with X-Y input
(:div class=code :)
/* Row-Column Scanning an 8x8 LED matrix with X-Y input This example controls an 8x8 LED matrix using two analog inputs created 27 May 2009 modified 29 Jun 2009 by Tom Igoe 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 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 Potentiometers: * center pins are attached to analog pins 0 and 1, respectively * side pins attached to +5V and ground, respectively. http://www.arduino.cc/en/Tutorial/RowColumnScanning see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more */
This example controls an 8x8 LED matrix using two analog inputs
created 27 May 2009 modified 29 Jun 2009 by Tom Igoe
// 2-dimensional array of row pin numbers: const int row[8] = { 2,7,19,5,18,12,16 };
This example works for the Lumex LDM-24488NI Matrix. See http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf for the pin connections
// 2-dimensional array of column pin numbers: const int col[8] = { 6,11,10,3,17,4,8,9 };
For other LED cathode column matrixes, you should only need to change the pin numbers in the row[] and column[] arrays
// 2-dimensional array of pixels: int pixels[8][8];
rows are the anodes cols are the cathodes ---------
// cursor position: int x = 5; int y = 5;
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.
void setup() { Serial.begin(9600); // initialize the I/O pins as outputs:
http://www.arduino.cc/en/Tutorial/RowColumnScanning
// 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); }
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);
}
} @]
// 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); } }
(:divend:)
modified 26 Jun 2009
modified 29 Jun 2009
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 ---------
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 ---------
Accelerometer: * X and Y axes attached to analog in 0 and 1
Potentiometers: * center pins are attached to analog pins 0 and 1, respectively * side pins attached to +5V and ground, respectively.
http://www.arduino.cc/en/Tutorial/RowColumnScanning
see http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
http://www.arduino.cc/en/Tutorial/RowColumnScanning
see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
// max and min values from the accelerometer, // found by experiment: const int sensorMin = 380; const int sensorMax = 620;
2,7,19,5,18,12,16 };
2,7,19,5,18,12,16 };
x = 7 - map(analogRead(0), sensorMin, sensorMax, 0, 7); y = map(analogRead(1), sensorMin, sensorMax, 0, 7);
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:
click the image to enlarge
click the image to enlarge.
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.
Although there are pre-made LED matrices, you can also make your own matrix from 64 LEDs, using the schematic as shown above.
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:
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:
Row-Column Scanning an 8x8 LED matrix with accelerometer for Arduino
Row-Column Scanning an 8x8 LED matrix with X-Y input
This example controls an 8x8 LED matrix using two inputs from an accelerometer.
This example controls an 8x8 LED matrix using two analog inputs
This example works for the Fairchild GMA2288C matrix. See
http://sigma.octopart.com/125394/datasheet/Fairchild-GMA2288C.pdf for the pin connections
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
see http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
9,8,7,6,16,17,18,19 };
2,7,19,5,18,12,16 };
13,12,11,10,5,4,3,2 };
6,11,10,3,17,4,8,9 };
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cellnr align=center:)
(:cellnr align=center:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cell align=centernr align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cell:)
(:cell align=center:)
(:cellnr:)
(:cellnr align=center:)
(:table border=1 font size=bigger:)
(:table border=1 align=center summary="Mapping: LED Matrix pin numbers to rows and columns to Arduino pin numbers":)
(:table border=1 font=+1:)
(:table border=1 font size=bigger:)
(:table border=1:)
(:table border=1 font=+1:)
Here's a matrix of the pin connections
Here's a matrix of the pin connections, based on the diagram above:
Row'''
Row
Column'''
Column
Arduino pin number'''
Arduino pin number
X
9
X
1
X
-
X
2
X
10
X
-
X
4
X
3
X
11
X
-
X
6
X
4
X
12
X
4
X
-
X
5
X
13
X
-
X
1
X
6
X
14
X
2
X
-
X
7
X
15
X
-
X
7
X
8
X
16
X
-
X
8
X
9
'''Matrix pin no.
Matrix pin no.
Row
Row'''
Column
Column'''
X
13
-
2
7 (:cell:)
12
(:cellnr:) 3 (:cell:)
2 (:cell:) 11
(:cellnr:) 4 (:cell:)
(: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
Matrix pin no.
'''Matrix pin no.
Arduino pin number
Arduino pin number'''
(cellnr:)
(:cellnr:)
(cellnr:)Matrix pin no.
(cellnr:) Matrix pin no.
-
-
-
-
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:)
Examples > Display
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:
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.
click the image to enlarge
Schematic:
click the image to enlarge
/*
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 a more complex example in the Arduino playground. Other examples can be found on Tom Igoe's blog: