This is the first LED matrix iv'e made since i got into Arduino. So i took my own approach to assemble it and to get it working. I did not look up any tutorials and i used stuff i had laying around to built it. It actually took me 3 months to completely understand how it works :).
I used:
- 1 old prototype board i had laying around.
- 1 Arduino pro mini.
- 16 white LED's i got from a chinese headlamp.
- 4 200ohm resistors (still can't remember why but i can't change them).
- 1 On/off switch.
- 1 Reset button.
Then i did the following:
- Made 8 LED rows.
- Connected the LED rows with the digital pins of the Arduino pro mini.
- Made a variable for the delay.
int delayAmount = 1;
- Made a variables for each of the rows.
int ledPinLow1 = 10;
int ledPinLow2 = 11;
int ledPinLow3 = 12;
int ledPinLow4 = 13;
int ledPinHigh1 = 6;
int ledPinHigh2 = 7;
int ledPinHigh3 = 8;
int ledPinHigh4 = 9;
- Made an imaginary table from 1 to 16 where each LED represents a number in the 4X4 matrix.
1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 |
- Made a function for each one of them open and assigned them one table number.
void ledOne() {
digitalWrite(ledPinLow4, HIGH);
digitalWrite(ledPinHigh2, HIGH);
digitalWrite(ledPinHigh3, HIGH);
digitalWrite(ledPinHigh4, HIGH);
}
void ledTwo() {
digitalWrite(ledPinLow4, HIGH);
digitalWrite(ledPinHigh1, HIGH);
digitalWrite(ledPinHigh3, HIGH);
digitalWrite(ledPinHigh4, HIGH);
}
void ledThree() {
digitalWrite(ledPinLow4, HIGH);
digitalWrite(ledPinHigh1, HIGH);
digitalWrite(ledPinHigh2, HIGH);
digitalWrite(ledPinHigh4, HIGH);
}
void ledFour() {
digitalWrite(ledPinLow4, HIGH);
digitalWrite(ledPinHigh1, HIGH);
digitalWrite(ledPinHigh2, HIGH);
digitalWrite(ledPinHigh3, HIGH);
}
void ledFive() {
digitalWrite(ledPinLow3, HIGH);
digitalWrite(ledPinHigh2, HIGH);
digitalWrite(ledPinHigh3, HIGH);
digitalWrite(ledPinHigh4, HIGH);
}
void ledSix() {
digitalWrite(ledPinLow3, HIGH);
digitalWrite(ledPinHigh1, HIGH);
digitalWrite(ledPinHigh3, HIGH);
digitalWrite(ledPinHigh4, HIGH);
}
void ledSeven() {
digitalWrite(ledPinLow3, HIGH);
digitalWrite(ledPinHigh1, HIGH);
digitalWrite(ledPinHigh2, HIGH);
digitalWrite(ledPinHigh4, HIGH);
}
void ledEight() {
digitalWrite(ledPinLow3, HIGH);
digitalWrite(ledPinHigh1, HIGH);
digitalWrite(ledPinHigh2, HIGH);
digitalWrite(ledPinHigh3, HIGH);
}
void ledNine() {
digitalWrite(ledPinLow2, HIGH);
digitalWrite(ledPinHigh2, HIGH);
digitalWrite(ledPinHigh3, HIGH);
digitalWrite(ledPinHigh4, HIGH);
}
void ledTen() {
digitalWrite(ledPinLow2, HIGH);
digitalWrite(ledPinHigh1, HIGH);
digitalWrite(ledPinHigh3, HIGH);
digitalWrite(ledPinHigh4, HIGH);
}
void ledEleven() {
digitalWrite(ledPinLow2, HIGH);
digitalWrite(ledPinHigh1, HIGH);
digitalWrite(ledPinHigh2, HIGH);
digitalWrite(ledPinHigh4, HIGH);
}
void ledTwelve() {
digitalWrite(ledPinLow2, HIGH);
digitalWrite(ledPinHigh1, HIGH);
digitalWrite(ledPinHigh2, HIGH);
digitalWrite(ledPinHigh3, HIGH);
}
void ledThirteen() {
digitalWrite(ledPinLow1, HIGH);
digitalWrite(ledPinHigh2, HIGH);
digitalWrite(ledPinHigh3, HIGH);
digitalWrite(ledPinHigh4, HIGH);
}
void ledFourteen() {
digitalWrite(ledPinLow1, HIGH);
digitalWrite(ledPinHigh1, HIGH);
digitalWrite(ledPinHigh3, HIGH);
digitalWrite(ledPinHigh4, HIGH);
}
void ledFifteen() {
digitalWrite(ledPinLow1, HIGH);
digitalWrite(ledPinHigh1, HIGH);
digitalWrite(ledPinHigh2, HIGH);
digitalWrite(ledPinHigh4, HIGH);
}
void ledSixteen() {
digitalWrite(ledPinLow1, HIGH);
digitalWrite(ledPinHigh1, HIGH);
digitalWrite(ledPinHigh2, HIGH);
digitalWrite(ledPinHigh3, HIGH);
}
- Made a function for all of them closed.
void ledClose() {
digitalWrite(ledPinLow1, LOW);
digitalWrite(ledPinLow2, LOW);
digitalWrite(ledPinLow3, LOW);
digitalWrite(ledPinLow4, LOW);
digitalWrite(ledPinHigh1, LOW);
digitalWrite(ledPinHigh2, LOW);
digitalWrite(ledPinHigh3, LOW);
digitalWrite(ledPinHigh4, LOW);
}
- Made a simple system that uses these functions to rapidly open and close the LED's so you can create "frames" to run inside a for loop, inside void loop to determine for how long a frame should last.
void loop() {
for (int i = 0; i < 100; i++) {
frame1();
delay(2);
}
}
void frame1() {
ledOne();
delay(delayAmount);
ledClose();
ledThree();
delay(delayAmount);
ledClose();
ledSix();
delay(delayAmount);
ledClose();
ledEight();
delay(delayAmount);
ledClose();
ledNine();
delay(delayAmount);
ledClose();
ledEleven();
delay(delayAmount);
ledClose();
ledFourteen();
delay(delayAmount);
ledClose();
ledSixteen();
delay(delayAmount);
ledClose();
}
Put all those frames together and you can have any animation you like, complete control without any libraries.
I still don't know if this is the right way to make a LED matrix but it works surprisingly well.