Skip to main content

LED displays

You will program a display to count numbers and then display your name! You will use circuit boards with all of the components to make the display work, so you can just plug them into the arduino and start programming immediately.

Find the Worksheet here: (PDF Document) LED Display Worksheet

The Worksheet requires you to start with a basic template program. Click and drag to select the program below, then copy and paste it into the Arduino Software

Dot Matrix Tutorial program

/*
* Connect Dot Matrix Shield
* 11_02_2015 Stephen Pithouse
*/
int colArray[] = {A4, 6, 9, 10, 3}; //Pins connected to columns
int rowArray[] = {11, A3, 12, 4, 8, 2, 7}; //Pins connected to rows
int pattern[7][5]; //Pattern is 7 cols. and 5 rows
int row[7]; //There are 7 rows
int numOfLetters = 2; int myWord[][7] = {{ //[numberOfLetters][7]
0b00100, //showLetter(0)
0b11100,
0b00100,
0b00100,
0b00100,
0b00100,
0b11111,
}
, {
0b01110, //showLetter(1)
0b10001,
0b00001,
0b00010,
0b00100,
0b01000,
0b11111,
}
};

void setup() {
pinMode(2, OUTPUT); //make all pins outputs
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(A5, OUTPUT);
pinMode(A4, OUTPUT);
pinMode(A3, OUTPUT);
}
void loop() { //Program starts here
showLetter(0);
}

void showLetter(int letter) { //Loads data from the array and sends it to be displayed
for (int a = 0; a < 7; ++a) row[a] = myWord[letter][a];
long timer = millis();
while (millis() - timer < 500) displayNow(); //Displays for 500ms
}

void scrollText(int scrollSpeed) { //input is a delay (in ms per screen) eg. 200
for (int a = 0; a <= (numOfLetters - 1) * 5; ++a) {
int startChar = a / 5; //Find start character
int startPos = a % 5; //Find position in start character
for (int k = 0; k < 7; ++k) row[k] = 0; //Clear old data
for (int b = 0; b < 5; ++b) { //repeat 5 times (for each bit)
for (int k = 0; k < 7; ++k) if (myWord[startChar][k] & 1 << (4 - (startPos + b))) row[k] |= ((1 << (4 - b))) & 0b11111;
if ((startPos + b) >= 4) { //gap between characters
startChar++; startPos -= 6; //5 means no gap
}
}
long timer = millis();
while (millis() - timer < scrollSpeed) displayNow(); //pause for current frame
}
}

void displayNow() {
for (int j = 0; j < 7; ++j) { //Scroll through rows
for (int i = 4; i >= 0; --i) { //Scroll through columns
if (row[j] & (1 << 4 - i)) { //In reverse order...
pattern[j][i] = 1; //LED should be ON
} else {
pattern[j][i] = 0; //LED should be OFF
}
}
}
for (int col = 0; col < 5; ++col) { //scroll through columns
digitalWrite(colArray[col], HIGH); //Make column active
for (int row = 0; row < 7; ++row) {
digitalWrite(rowArray[row], !pattern[row][col]); //Turn on only desired LEDs in column
if(pattern[row][col]) delayMicroseconds(400); //Keep each dot lit up for 400us
digitalWrite(rowArray[row], 1);
}
clearAll();
}
}

void clearAll() { //turn all dots off:
for (int col = 0; col < 5; ++col) digitalWrite(colArray[col], 0);
for (int row = 0; row < 7; ++row) digitalWrite(rowArray[row], 1);
}