Con questo progetto vi mostro come controllare una pallina su una matrice led 8×8.
Con i due potenziometri puoi muovere la pallina sugli assi X e Y della matrice.
In questo progetto imparerai come utilizzare una matrice di LED e come leggere i valori di un potenziometro.
- Livello – Principiante/Intermedio 40%
- Durata – 45/60 Min 60%
- Costi – € 36,51 euro completo 30%
Passaggio 1: forniture
- 1X Arduino UNO
- 1X Paneboard
- 13X Cavi di collegamento M/M
- 1X Matrice led 8×8
- 2X Potenziometro 10K
Passaggio 2: costruisci e cabla
Passaggio 3: programmazione
Se tutto è collegato correttamente puoi iniziare a scrivere il programma.
È un programma abbastanza grande ma è per lo più costante con solo pochi valori che cambiano.
Questo codice è ora creato per una matrice di led che ha solo gli assi X e Y.
Se vuoi usare anche un asse Z devi collegare un potenziometro extra e poi regolare il codice in modo che i valori possano essere letti.
Puoi copiare il codice qui sotto, ma ti consigliamo di digitarlo tu stesso poiché ne imparerai di più.
#include LedControl.h
//qui chiamiamo la matrice LED e i pin I/O che può controllare
Controllo Led L = Controllo Led(12, 11, 10);
//qui definiamo i potenziometri
const int jar = 0;
cost int pot2 = 1;
//qui ci assicuriamo di poter memorizzare i valori del potenziometro
valore int;
int jarvalue2;
void setup () {
//qui impostiamo la matrice di led spegnendola quindi regolando l'intensità e cancellando la memoria
L.arresto(0, falso);
L.setIntensità(0, 4);
L.clearDisplay(0);
}
void loop () {
//qui diciamo che Arduino dovrebbe leggere le porte analogiche per i valori
valorepot = analogRead(pot);
//qui definiamo i valori che il potenziometro può indicare
valorepot = map(valorepot, 0, 1000, 0, 7);
valorepot2 = analogRead(pot2);
potvalue2 = mappa(potvalue2, 0, 1000, 0, 7);
//qui controlliamo se entrambi i valori sono uguali a 0, in tal caso si accende la spia 0,0
//Quello che in realtà dice qui è se 1 e 2 sono uguali a 0, allora 0,0 si attiva
if(potvalue == 0 && potvalue2 == 0){
riga intera = 0;
colonna intera = 0;
L.setLed(0, riga, col, vero);
}
//qui controlliamo se uno di quei valori non è 0 se true 0,0 si spegne
//questo processo lo ripetiamo continuamente finché tutte le coordinate non sono definite
//Quello che dice qui è se 1 o 2 non è uguale a 0, allora 0,0 si spegne
if(valorepot!= 0 ||valorepot2!= 0){
riga intera = 0;
colonna intera = 0;
L.setLed(0, riga, col, false);
}
if(potvalue == 1 && potvalue2 == 0){
riga intera = 1;
colonna intera = 0;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 1 ||valorepot2!= 0){
riga intera = 1;
colonna intera = 0;
L.setLed(0, riga, col, false);
}
if(potvalue == 2 && potvalue2 == 0){
riga intera = 2;
colonna intera = 0;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 2 ||valorepot2!= 0){
riga intera = 2;
colonna intera = 0;
L.setLed(0, riga, col, false);
}
if(potvalue == 3 && potvalue2 == 0){
riga intera = 3;
colonna intera = 0;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 3 ||valorepot2!= 0){
riga intera = 3;
colonna intera = 0;
L.setLed(0, riga, col, false);
}
if(potvalue == 4 && potvalue2 == 0){
riga intera = 4;
colonna intera = 0;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 4 ||valorepot2!= 0){
riga intera = 4;
colonna intera = 0;
L.setLed(0, riga, col, false);
}
if(potvalue == 5 && potvalue2 == 0){
riga intera = 5;
colonna intera = 0;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 5 ||valorepot2!= 0){
riga intera = 5;
colonna intera = 0;
L.setLed(0, riga, col, false);
}
if(potvalue == 6 && potvalue2 == 0){
riga intera = 6;
colonna intera = 0;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 6 ||valorepot2!= 0){
riga intera = 6;
colonna intera = 0;
L.setLed(0, riga, col, false);
}
if(potvalue == 7 && potvalue2 == 0){
riga intera = 7;
colonna intera = 0;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 7 ||valorepot2!= 0){
riga intera = 7;
colonna intera = 0;
L.setLed(0, riga, col, false);
}
if(potvalue == 0 && potvalue2 == 1){
riga intera = 0;
colonna intera = 1;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 0 ||valorepot2!= 1){
riga intera = 0;
colonna intera = 1;
L.setLed(0, riga, col, false);
}
if(potvalue == 1 && potvalue2 == 1){
riga intera = 1;
colonna intera = 1;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 1 ||valorepot2!= 1){
riga intera = 1;
colonna intera = 1;
L.setLed(0, riga, col, false);
}
if(potvalue == 2 && potvalue2 == 1){
riga intera = 2;
colonna intera = 1;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 2 ||valorepot2!= 1){
riga intera = 2;
colonna intera = 1;
L.setLed(0, riga, col, false);
}
if(potvalue == 3 && potvalue2 == 1){
riga intera = 3;
colonna intera = 1;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 3 ||valorepot2!= 1){
riga intera = 3;
colonna intera = 1;
L.setLed(0, riga, col, false);
}
if(potvalue == 4 && potvalue2 == 1){
riga intera = 4;
colonna intera = 1;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 4 ||valorepot2!= 1){
riga intera = 4;
colonna intera = 1;
L.setLed(0, riga, col, false);
}
if(potvalue == 5 && potvalue2 == 1){
riga intera = 5;
colonna intera = 1;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 5 ||valorepot2!= 1){
riga intera = 5;
colonna intera = 1;
L.setLed(0, riga, col, false);
}
if(potvalue == 6 && potvalue2 == 1){
riga intera = 6;
colonna intera = 1;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 6 ||valorepot2!= 1){
riga intera = 6;
colonna intera = 1;
L.setLed(0, riga, col, false);
}
if(potvalue == 7 && potvalue2 == 1){
riga intera = 7;
colonna intera = 1;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 7 ||valorepot2!= 1){
riga intera = 7;
colonna intera = 1;
L.setLed(0, riga, col, false);
}
if(potvalue == 0 && potvalue2 == 2){
riga intera = 0;
colonna intera = 2;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 0 ||valorepot2!= 2){
riga intera = 0;
colonna intera = 2;
L.setLed(0, riga, col, false);
}
if(potvalue == 1 && potvalue2 == 2){
riga intera = 1;
colonna intera = 2;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 1 ||valorepot2!= 2){
riga intera = 1;
colonna intera = 2;
L.setLed(0, riga, col, false);
}
if(potvalue == 2 && potvalue2 == 2){
riga intera = 2;
colonna intera = 2;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 2 ||valorepot2!= 2){
riga intera = 2;
colonna intera = 2;
L.setLed(0, riga, col, false);
}
if(potvalue == 3 && potvalue2 == 2){
riga intera = 3;
colonna intera = 2;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 3 ||valorepot2!= 2){
riga intera = 3;
colonna intera = 2;
L.setLed(0, riga, col, false);
}
if(potvalue == 4 && potvalue2 == 2){
riga intera = 4;
colonna intera = 2;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 4 ||valorepot2!= 2){
riga intera = 4;
colonna intera = 2;
L.setLed(0, riga, col, false);
}
if(potvalue == 5 && potvalue2 == 2){
riga intera = 5;
colonna intera = 2;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 5 ||valorepot2!= 2){
riga intera = 5;
colonna intera = 2;
L.setLed(0, riga, col, false);
}
if(potvalue == 6 && potvalue2 == 2){
riga intera = 6;
colonna intera = 2;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 6 ||valorepot2!= 2){
riga intera = 6;
colonna intera = 2;
L.setLed(0, riga, col, false);
}
if(potvalue == 7 && potvalue2 == 2){
riga intera = 7;
colonna intera = 2;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 7 ||valorepot2!= 2){
riga intera = 7;
colonna intera = 2;
L.setLed(0, riga, col, false);
}
if(potvalue == 0 && potvalue2 == 3){
riga intera = 0;
colonna intera = 3;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 0 ||valorepot2!= 3){
riga intera = 0;
colonna intera = 3;
L.setLed(0, riga, col, false);
}
if(potvalue == 1 && potvalue2 == 3){
riga intera = 1;
colonna intera = 3;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 1 ||valorepot2!= 3){
riga intera = 1;
colonna intera = 3;
L.setLed(0, riga, col, false);
}
if(potvalue == 2 && potvalue2 == 3){
riga intera = 2;
colonna intera = 3;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 2 ||valorepot2!= 3){
riga intera = 2;
colonna intera = 3;
L.setLed(0, riga, col, false);
}
if(potvalue == 3 && potvalue2 == 3){
riga intera = 3;
colonna intera = 3;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 3 ||valorepot2!= 3){
riga intera = 3;
colonna intera = 3;
L.setLed(0, riga, col, false);
}
if(potvalue == 4 && potvalue2 == 3){
riga intera = 4;
colonna intera = 3;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 4 ||valorepot2!= 3){
riga intera = 4;
colonna intera = 3;
L.setLed(0, riga, col, false);
}
if(potvalue == 5 && potvalue2 == 3){
riga intera = 5;
colonna intera = 3;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 5 ||valorepot2!= 3){
riga intera = 5;
colonna intera = 3;
L.setLed(0, riga, col, false);
}
if(potvalue == 6 && potvalue2 == 3){
riga intera = 6;
colonna intera = 3;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 6 ||valorepot2!= 3){
riga intera = 6;
colonna intera = 3;
L.setLed(0, riga, col, false);
}
if(potvalue == 7 && potvalue2 == 3){
riga intera = 7;
colonna intera = 3;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 7 ||valorepot2!= 3){
riga intera = 7;
colonna intera = 3;
L.setLed(0, riga, col, false);
}
if(potvalue == 0 && potvalue2 == 4){
riga intera = 0;
colonna intera = 4;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 0 ||valorepot2!= 4){
riga intera = 0;
colonna intera = 4;
L.setLed(0, riga, col, false);
}
if(potvalue == 1 && potvalue2 == 4){
riga intera = 1;
colonna intera = 4;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 1 ||valorepot2!= 4){
riga intera = 1;
colonna intera = 4;
L.setLed(0, riga, col, false);
}
if(potvalue == 2 && potvalue2 == 4){
riga intera = 2;
colonna intera = 4;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 2 ||valorepot2!= 4){
riga intera = 2;
colonna intera = 4;
L.setLed(0, riga, col, false);
}
if(potvalue == 3 && potvalue2 == 4){
riga intera = 3;
colonna intera = 4;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 3 ||valorepot2!= 4){
riga intera = 3;
colonna intera = 4;
L.setLed(0, riga, col, false);
}
if(potvalue == 4 && potvalue2 == 4){
riga intera = 4;
colonna intera = 4;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 4 ||valorepot2!= 4){
riga intera = 4;
colonna intera = 4;
L.setLed(0, riga, col, false);
}
if(potvalue == 5 && potvalue2 == 4){
riga intera = 5;
colonna intera = 4;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 5 ||valorepot2!= 4){
riga intera = 5;
colonna intera = 4;
L.setLed(0, riga, col, false);
}
if(potvalue == 6 && potvalue2 == 4){
riga intera = 6;
colonna intera = 4;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 6 ||valorepot2!= 4){
riga intera = 6;
colonna intera = 4;
L.setLed(0, riga, col, false);
}
if(potvalue == 7 && potvalue2 == 4){
riga intera = 7;
colonna intera = 4;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 7 ||valorepot2!= 4){
riga intera = 7;
colonna intera = 4;
L.setLed(0, riga, col, false);
}
if(potvalue == 0 && potvalue2 == 5){
riga intera = 0;
colonna intera = 5;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 0 ||valorepot2!= 5){
riga intera = 0;
colonna intera = 5;
L.setLed(0, riga, col, false);
}
if(potvalue == 1 && potvalue2 == 5){
riga intera = 1;
colonna intera = 5;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 1 ||valorepot2!= 5){
riga intera = 1;
colonna intera = 5;
L.setLed(0, riga, col, false);
}
if(potvalue == 2 && potvalue2 == 5){
riga intera = 2;
colonna intera = 5;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 2 ||valorepot2!= 5){
riga intera = 2;
colonna intera = 5;
L.setLed(0, riga, col, false);
}
if(potvalue == 3 && potvalue2 == 5){
riga intera = 3;
colonna intera = 5;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 3 ||valorepot2!= 5){
riga intera = 3;
colonna intera = 5;
L.setLed(0, riga, col, false);
}
if(potvalue == 4 && potvalue2 == 5){
riga intera = 4;
colonna intera = 5;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 4 ||valorepot2!= 5){
riga intera = 4;
colonna intera = 5;
L.setLed(0, riga, col, false);
}
if(potvalue == 5 && potvalue2 == 5){
riga intera = 5;
colonna intera = 5;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 5 ||valorepot2!= 5){
riga intera = 5;
colonna intera = 5;
L.setLed(0, riga, col, false);
}
if(potvalue == 6 && potvalue2 == 5){
riga intera = 6;
colonna intera = 5;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 6 ||valorepot2!= 5){
riga intera = 6;
colonna intera = 5;
L.setLed(0, riga, col, false);
}
if(potvalue == 7 && potvalue2 == 5){
riga intera = 7;
colonna intera = 5;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 7 ||valorepot2!= 5){
riga intera = 7;
colonna intera = 5;
L.setLed(0, riga, col, false);
}
if(potvalue == 0 && potvalue2 == 6){
riga intera = 0;
colonna intera = 6;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 0 ||valorepot2!= 6){
riga intera = 0;
colonna intera = 6;
L.setLed(0, riga, col, false);
}
if(potvalue == 1 && potvalue2 == 6){
riga intera = 1;
colonna intera = 6;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 1 ||valorepot2!= 6){
riga intera = 1;
colonna intera = 6;
L.setLed(0, riga, col, false);
}
if(potvalue == 2 && potvalue2 == 6){
riga intera = 2;
colonna intera = 6;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 2 ||valorepot2!= 6){
riga intera = 2;
colonna intera = 6;
L.setLed(0, riga, col, false);
}
if(potvalue == 3 && potvalue2 == 6){
riga intera = 3;
colonna intera = 6;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 3 ||valorepot2!= 6){
riga intera = 3;
colonna intera = 6;
L.setLed(0, riga, col, false);
}
if(potvalue == 4 && potvalue2 == 6){
riga intera = 4;
colonna intera = 6;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 4 ||valorepot2!= 6){
riga intera = 4;
colonna intera = 6;
L.setLed(0, riga, col, false);
}
if(potvalue == 5 && potvalue2 == 6){
riga intera = 5;
colonna intera = 6;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 5 ||valorepot2!= 6){
riga intera = 5;
colonna intera = 6;
L.setLed(0, riga, col, false);
}
if(potvalue == 6 && potvalue2 == 6){
riga intera = 6;
colonna intera = 6;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 6 ||valorepot2!= 6){
riga intera = 6;
colonna intera = 6;
L.setLed(0, riga, col, false);
}
if(potvalue == 7 && potvalue2 == 6){
riga intera = 7;
colonna intera = 6;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 7 ||valorepot2!= 6){
riga intera = 7;
colonna intera = 6;
L.setLed(0, riga, col, false);
}
if(potvalue == 0 && potvalue2 == 7){
riga intera = 0;
colonna intera = 7;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 0 ||valorepot2!= 7){
riga intera = 0;
colonna intera = 7;
L.setLed(0, riga, col, false);
}
if(potvalue == 1 && potvalue2 == 7){
riga intera = 1;
colonna intera = 7;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 1 ||valorepot2!= 7){
riga intera = 1;
colonna intera = 7;
L.setLed(0, riga, col, false);
}
if(potvalue == 2 && potvalue2 == 7){
riga intera = 2;
colonna intera = 7;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 2 ||valorepot2!= 7){
riga intera = 2;
colonna intera = 7;
L.setLed(0, riga, col, false);
}
if(potvalue == 3 && potvalue2 == 7){
riga intera = 3;
colonna intera = 7;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 3 ||valorepot2!= 7){
riga intera = 3;
colonna intera = 7;
L.setLed(0, riga, col, false);
}
if(potvalue == 4 && potvalue2 == 7){
riga intera = 4;
colonna intera = 7;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 4 ||valorepot2!= 7){
riga intera = 4;
colonna intera = 7;
L.setLed(0, riga, col, false);
}
if(potvalue == 5 && potvalue2 == 7){
riga intera = 5;
colonna intera = 7;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 5 ||valorepot2!= 7){
riga intera = 5;
colonna intera = 7;
L.setLed(0, riga, col, false);
}
if(potvalue == 6 && potvalue2 == 7){
riga intera = 6;
colonna intera = 7;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 6 ||valorepot2!= 7){
riga intera = 6;
colonna intera = 7;
L.setLed(0, riga, col, false);
}
if(potvalue == 7 && potvalue2 == 7){
riga intera = 7;
colonna intera = 7;
L.setLed(0, riga, col, vero);
}
if(valorepot!= 7 ||valorepot2!= 7){
riga intera = 7;
colonna intera = 7;
L.setLed(0, riga, col, false);
}
}
Ciao, da dove viene ledcontrol.h? sono un novizio
Grazie in anticipo!
Apri il software IDE di Arduino e fai clic su schizzo. Quindi usa la libreria. Quindi gestisci le librerie. Quindi apre Library Manager. Quindi cerchi: LedControl in alto. Seleziona quello in alto. Fai attenzione! DEVE essere stato realizzato da Eberhard Fahle.
Prego!