#include <LedControl.h>
LedControl lc = LedControl(11, 13, 10, 1);
#define POTX A0 //Asse orizzontale
#define POTY A1 //Asse verticale
//Posizione iniziale del LED
int x = 3;
int y = 3;
//Funzione per leggere il potinziometro
int leggiPOTX(){
int valore =analogRead(A0); //valore da 0 a 1023
//Zona movimento negativo
if (valore < 300){
return -1;
}
//Zona movimento positivo
if (valore > 700){
return 1;
}
//Zona morta
return 0;
}
//Funzione per leggere il potinziometro
int leggiPOTY(){
int valore = analogRead(A1);
if (valore < 300){
return -1;
}
if (valore > 700){
return 1;
}
return 0;
}
void controlloPosizione(){
//Movimento sull'asse X
x = x + leggiPOTX();
//Controlla limiti Asse X
if (x < 0) x = 0;
if (x > 7) x = 7;
//Movimento sull'asse Y
y = y + leggiPOTY();
//Controlla limiti Asse Y
if (y < 0) y = 0;
if (y > 7) y = 7;
}
void setup() {
// put your setup code here, to run once:
lc.clearDisplay(0);//polire la matrice
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.setLed(0, 3, 3, true);
}
void loop() {
// put your main code here, to run repeatedly:
controlloPosizione();
lc.clearDisplay(0);//polire la matrice
lc.setLed(0, x, y, true);
// Per rendere il movimento più lento è liggipile
delay(300);
}