With this project I show how you can control a ball on an 8 × 8 LED matrix.
With the two potentiometers you can move the ball over the X and Y axis of the matrix.
In this project you will learn how to use an LED matrix and how to read the values of a potentiometer.
- Level - Beginner / Intermediate 40%
- Duration - 45/60 Min 60%
- Costs - € 36,51 euros complete 30%
Step 1: Requirements
- 1X Arduino UNO
- 1X Breadboard
- 13 times M/M jumper wires
- 1X 8×8 LED matrix
- 2X 10K potentiometer
Step 2: Building and Wiring
Step 3: Programming
If everything is connected correctly you can start writing the program.
It is a fairly large program but is mainly constant with only a few values that change.
This code is now made for an LED matrix that only has an X and Y axis.
If you also want to use a Z axis you have to connect an extra potentiometer and then adjust the code so that the values can be read.
You can copy the code below, but we recommend typing it yourself as you learn more from this.
#include LedControl.h
// here we give the LED matrix a name and the I / O pins that it can control
LedControl L = LedControl (12, 11, 10);
// here we define the potentiometers
const int jar = 0;
const int pot2 = 1;
// here we make sure that we can store the values of the potentiometer
int potvalue;
int jarvalue2;
void setup () {
// here we set the led matrix by turning it off then adjust the intensity and clear the memory
L.shutdown (0, false);
L.setIntensity (0, 4);
L.clearDisplay (0);
}
void loop () {
// here we say that the Arduino should read the analog ports for values
potvalue = analogRead (pot);
// here we define the values that the pot meter can indicate
potvalue = map (potvalue, 0, 1000, 0, 7);
potvalue2 = analogRead (pot2);
potvalue2 = map (potvalue2, 0, 1000, 0, 7);
// here we check if both values are equal to 0 if yes light 0,0 comes on
// so what is actually here is if 1 and 2 are equal to 0 then 0,0 will be turned on
if (potvalue == 0 && potvalue2 == 0) {
int row = 0;
int col = 0;
L.setLed (0, row, col, true);
}
// here we look if one of those values is not 0 if that is true 0,0 goes out
// we keep repeating this process all the time until all coordinates are defined
// what it says here is if 1 or 2 is not equal to 0 then 0,0 goes out
if (potvalue! = 0 || potvalue2! = 0) {
int row = 0;
int col = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 0) {
int row = 1;
int col = 0;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 0) {
int row = 1;
int col = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 0) {
int row = 2;
int col = 0;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 0) {
int row = 2;
int col = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 0) {
int row = 3;
int col = 0;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 0) {
int row = 3;
int col = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 0) {
int row = 4;
int col = 0;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 0) {
int row = 4;
int col = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 0) {
int row = 5;
int col = 0;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 0) {
int row = 5;
int col = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 0) {
int row = 6;
int col = 0;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 0) {
int row = 6;
int col = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 0) {
int row = 7;
int col = 0;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 0) {
int row = 7;
int col = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 0 && potvalue2 == 1) {
int row = 0;
int col = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 0 || potvalue2! = 1) {
int row = 0;
int col = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 1) {
int row = 1;
int col = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 1) {
int row = 1;
int col = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 1) {
int row = 2;
int col = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 1) {
int row = 2;
int col = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 1) {
int row = 3;
int col = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 1) {
int row = 3;
int col = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 1) {
int row = 4;
int col = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 1) {
int row = 4;
int col = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 1) {
int row = 5;
int col = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 1) {
int row = 5;
int col = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 1) {
int row = 6;
int col = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 1) {
int row = 6;
int col = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 1) {
int row = 7;
int col = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 1) {
int row = 7;
int col = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 0 && potvalue2 == 2) {
int row = 0;
int col = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 0 || potvalue2! = 2) {
int row = 0;
int col = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 2) {
int row = 1;
int col = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 2) {
int row = 1;
int col = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 2) {
int row = 2;
int col = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 2) {
int row = 2;
int col = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 2) {
int row = 3;
int col = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 2) {
int row = 3;
int col = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 2) {
int row = 4;
int col = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 2) {
int row = 4;
int col = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 2) {
int row = 5;
int col = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 2) {
int row = 5;
int col = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 2) {
int row = 6;
int col = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 2) {
int row = 6;
int col = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 2) {
int row = 7;
int col = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 2) {
int row = 7;
int col = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 0 && potvalue2 == 3) {
int row = 0;
int col = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 0 || potvalue2! = 3) {
int row = 0;
int col = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 3) {
int row = 1;
int col = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 3) {
int row = 1;
int col = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 3) {
int row = 2;
int col = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 3) {
int row = 2;
int col = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 3) {
int row = 3;
int col = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 3) {
int row = 3;
int col = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 3) {
int row = 4;
int col = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 3) {
int row = 4;
int col = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 3) {
int row = 5;
int col = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 3) {
int row = 5;
int col = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 3) {
int row = 6;
int col = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 3) {
int row = 6;
int col = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 3) {
int row = 7;
int col = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 3) {
int row = 7;
int col = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 0 && potvalue2 == 4) {
int row = 0;
int col = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 0 || potvalue2! = 4) {
int row = 0;
int col = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 4) {
int row = 1;
int col = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 4) {
int row = 1;
int col = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 4) {
int row = 2;
int col = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 4) {
int row = 2;
int col = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 4) {
int row = 3;
int col = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 4) {
int row = 3;
int col = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 4) {
int row = 4;
int col = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 4) {
int row = 4;
int col = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 4) {
int row = 5;
int col = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 4) {
int row = 5;
int col = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 4) {
int row = 6;
int col = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 4) {
int row = 6;
int col = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 4) {
int row = 7;
int col = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 4) {
int row = 7;
int col = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 0 && potvalue2 == 5) {
int row = 0;
int col = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 0 || potvalue2! = 5) {
int row = 0;
int col = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 5) {
int row = 1;
int col = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 5) {
int row = 1;
int col = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 5) {
int row = 2;
int col = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 5) {
int row = 2;
int col = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 5) {
int row = 3;
int col = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 5) {
int row = 3;
int col = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 5) {
int row = 4;
int col = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 5) {
int row = 4;
int col = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 5) {
int row = 5;
int col = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 5) {
int row = 5;
int col = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 5) {
int row = 6;
int col = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 5) {
int row = 6;
int col = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 5) {
int row = 7;
int col = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 5) {
int row = 7;
int col = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 0 && potvalue2 == 6) {
int row = 0;
int col = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 0 || potvalue2! = 6) {
int row = 0;
int col = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 6) {
int row = 1;
int col = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 6) {
int row = 1;
int col = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 6) {
int row = 2;
int col = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 6) {
int row = 2;
int col = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 6) {
int row = 3;
int col = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 6) {
int row = 3;
int col = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 6) {
int row = 4;
int col = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 6) {
int row = 4;
int col = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 6) {
int row = 5;
int col = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 6) {
int row = 5;
int col = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 6) {
int row = 6;
int col = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 6) {
int row = 6;
int col = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 6) {
int row = 7;
int col = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 6) {
int row = 7;
int col = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 0 && potvalue2 == 7) {
int row = 0;
int col = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 0 || potvalue2! = 7) {
int row = 0;
int col = 7;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 7) {
int row = 1;
int col = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 7) {
int row = 1;
int col = 7;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 7) {
int row = 2;
int col = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 7) {
int row = 2;
int col = 7;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 7) {
int row = 3;
int col = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 7) {
int row = 3;
int col = 7;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 7) {
int row = 4;
int col = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 7) {
int row = 4;
int col = 7;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 7) {
int row = 5;
int col = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 7) {
int row = 5;
int col = 7;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 7) {
int row = 6;
int col = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 7) {
int row = 6;
int col = 7;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 7) {
int row = 7;
int col = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 7) {
int row = 7;
int col = 7;
L.setLed (0, row, col, false);
}
}
Hi, where does ledcontrol.h come from? I am a beginner 😉
Thank you in advance!
Open the arduino IDE software and click sketch. Then use library. Then manage libraries. Then he opens Library Manager. Then you search for: LedControl at the top. Select the top one. Pay attention! It MUST have been made by Eberhard Fahle.
You're welcome! 😉