Buonpomeriggio, vorrei sapere se potreste aiutarmi a risolvere questo problema a cui non riesco a trovare una soluzione, ho provato a usare anche millis() come avevo letto in altri argomenti di questo forum ma non ha funzionato, stavo facendo un codice che richiede una specie di animazione nello schermo lcd ma allo stesso tempo deve controllare se il valore dell'encoder rotativo collegato cambia. Come posso fare? Grazie in anticipo per le risposte. Il codice in questione è questo:
int t_animazione5 = 1;
int pinA = 5;
int pinB = 6;
int pinALast;
int aVal;
int pinBLast;
int bVal;
#define intervalloa 500
#define intervallob 1000
#define intervalloc 1500
#define intervallod 2000
#define intervalloe 2500
#define intervallof 3000
#define intervallog 3500
#define intervalloh 4000
#define intervalloi 4500
unsigned long t0a, dta;
unsigned long t0b, dtb;
unsigned long t0c, dtc;
unsigned long t0d, dtd;
unsigned long t0e, dte;
unsigned long t0f, dtf;
unsigned long t0g, dtg;
unsigned long t0h, dth;
unsigned long t0i, dti;
byte rotellina_1[8] = {
0b00000,
0b11111,
0b00000,
0b00100,
0b00100,
0b00100,
0b00100,
0b00000
};
byte rotellina_2[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b00000
};
byte rotellina_3[8] = {
0b00000,
0b11111,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00011
};
byte rotellina_4[8] = {
0b00000,
0b00000,
0b10000,
0b01000,
0b00100,
0b00100,
0b11010,
0b00010
};
byte rotellina_5[8] = {
0b00011,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b00000
};
byte rotellina_6[8] = {
0b00010,
0b11010,
0b00100,
0b00100,
0b01000,
0b10000,
0b00000,
0b00000
};
byte rotellina_7[8] = {
0b00000,
0b00100,
0b00100,
0b00100,
0b00100,
0b00000,
0b11111,
0b00000
};
byte rotellina_8[8] = {
0b01000,
0b01011,
0b00100,
0b00100,
0b00010,
0b00001,
0b00000,
0b00000
};
byte rotellina_9[8] = {
0b11000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b00000
};
byte rotellina_10[8] = {
0b00000,
0b00000,
0b00001,
0b00010,
0b00100,
0b00100,
0b01011,
0b01000
};
byte rotellina_11[8] = {
0b00000,
0b11111,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11000
};
byte girare_1[8] = {
0b00000,
0b11111,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
byte girare_2[8] = {
0b00000,
0b00000,
0b10010,
0b01010,
0b00010,
0b11110,
0b00000,
0b00000
};
byte girare_3[8] = {
0b00000,
0b00000,
0b01111,
0b01000,
0b01010,
0b01001,
0b00000,
0b00000
};
byte girare_4[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b00000
};
byte orologio_1[8] = {
0b00000,
0b00000,
0b00001,
0b00010,
0b00100,
0b00100,
0b01000,
0b01000
};
byte orologio_2[8] = {
0b00000,
0b11111,
0b00000,
0b00100,
0b00100,
0b00100,
0b00100,
0b00100
};
byte orologio_3[8] = {
0b00000,
0b00000,
0b10000,
0b01000,
0b00100,
0b00100,
0b00010,
0b00010
};
byte orologio_4[8] = {
0b01000,
0b01000,
0b00100,
0b00100,
0b00010,
0b00001,
0b00000,
0b00000
};
byte orologio_5[8] = {
0b00100,
0b00010,
0b00001,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111
};
byte orologio_6[8] = {
0b00010,
0b00010,
0b00100,
0b00100,
0b01000,
0b10000,
0b00000,
0b00000
};
void funzione (){
t0a = millis();
t0b = millis();
t0c = millis();
t0d = millis();
t0e = millis();
t0f = millis();
t0g = millis();
t0h = millis();
t0i = millis();
t0j = millis();
t0k = millis();
pinALast = digitalRead(pinA);
aVal = digitalRead(pinA);
while(aVal != pinALast){
dta = millis() - t0a;
dtb = millis() - t0b;
dtc = millis() - t0c;
dtd = millis() - t0d;
dte = millis() - t0e;
dtf = millis() - t0f;
dtg = millis() - t0g;
dth = millis() - t0h;
dti = millis() - t0i;
dtj = millis() - t0j;
dtk = millis() - t0k;
aVal = digitalRead(pinA);
lcd.setCursor(3,0);
lcd.print("Tutorial");
lcd.clear();
lcd.setCursor (3,0);
lcd.print("Ruotare la");
lcd.setCursor(3,1);
lcd.print("Rotellina");
t0a = millis();
lcd.createChar(0,orologio_1);
lcd.setCursor(0,0);
lcd.write(0);
lcd.createChar(1,girare_1);
lcd.setCursor(1,0);
lcd.write(1);
lcd.createChar(2,girare_2);
lcd.setCursor(2,0);
lcd.write(2);
lcd.createChar(3,girare_3);
lcd.setCursor(0,1);
lcd.write(3);
lcd.createChar(4,girare_4);
lcd.setCursor(1,1);
lcd.write(4);
lcd.createChar(5,orologio_6);
lcd.setCursor(2,1);
lcd.write(5);
if(dta >= intervalloa){
t0a = millis();
aVal = digitalRead(pinA);
lcd.createChar(0,orologio_1);
lcd.setCursor(0,0);
lcd.write(0);
lcd.createChar(1,rotellina_3);
lcd.setCursor(1,0);
lcd.write(1);
lcd.createChar(2,rotellina_4);
lcd.setCursor(2,0);
lcd.write(2);
lcd.createChar(3,orologio_4);
lcd.setCursor(0,1);
lcd.write(3);
lcd.createChar(4,rotellina_2);
lcd.setCursor(1,1);
lcd.write(4);
lcd.createChar(5,orologio_6);
lcd.setCursor(2,1);
lcd.write(5);
}
if(dtb >= intervallob){
t0b = millis();
aVal = digitalRead(pinA);
lcd.createChar(0,orologio_1);
lcd.setCursor(0,0);
lcd.write(0);
lcd.createChar(1,girare_1);
lcd.setCursor(1,0);
lcd.write(1);
lcd.createChar(2,girare_2);
lcd.setCursor(2,0);
lcd.write(2);
lcd.createChar(3,girare_3);
lcd.setCursor(0,1);
lcd.write(3);
lcd.createChar(4,girare_4);
lcd.setCursor(1,1);
lcd.write(4);
lcd.createChar(5,orologio_6);
lcd.setCursor(2,1);
lcd.write(5);
}
if(dtc >= intervalloc){
t0c = millis();
aVal = digitalRead(pinA);
lcd.createChar(0,orologio_1);
lcd.setCursor(0,0);
lcd.write(0);
lcd.createChar(1,girare_1);
lcd.setCursor(1,0);
lcd.write(1);
lcd.createChar(2,orologio_3);
lcd.setCursor(2,0);
lcd.write(2);
lcd.createChar(3,orologio_4);
lcd.setCursor(0,1);
lcd.write(3);
lcd.createChar(4,rotellina_5);
lcd.setCursor(1,1);
lcd.write(4);
lcd.createChar(5,rotellina_6);
lcd.setCursor(2,1);
lcd.write(5);
}
if(dtd >= intervallod){
t0d = millis();
aVal = digitalRead(pinA);
lcd.createChar(0,orologio_1);
lcd.setCursor(0,0);
lcd.write(0);
lcd.createChar(1,girare_1);
lcd.setCursor(1,0);
lcd.write(1);
lcd.createChar(2,girare_2);
lcd.setCursor(2,0);
lcd.write(2);
lcd.createChar(3,girare_3);
lcd.setCursor(0,1);
lcd.write(3);
lcd.createChar(4,girare_4);
lcd.setCursor(1,1);
lcd.write(4);
lcd.createChar(5,orologio_6);
lcd.setCursor(2,1);
lcd.write(5);
}
if(dte >= intervalloe){
t0e = millis();
aVal = digitalRead(pinA);
lcd.createChar(0,orologio_1);
lcd.setCursor(0,0);
lcd.write(0);
lcd.createChar(1,girare_1);
lcd.setCursor(1,0);
lcd.write(1);
lcd.createChar(2,orologio_3);
lcd.setCursor(2,0);
lcd.write(2);
lcd.createChar(3,orologio_4);
lcd.setCursor(0,1);
lcd.write(3);
lcd.createChar(4,rotellina_7);
lcd.setCursor(1,1);
lcd.write(4);
lcd.createChar(5,orologio_6);
lcd.setCursor(2,1);
lcd.write(5);
}
if(dtf >= intervallof){
t0f = millis();
aVal = digitalRead(pinA);
lcd.createChar(0,orologio_1);
lcd.setCursor(0,0);
lcd.write(0);
lcd.createChar(1,girare_1);
lcd.setCursor(1,0);
lcd.write(1);
lcd.createChar(2,girare_2);
lcd.setCursor(2,0);
lcd.write(2);
lcd.createChar(3,girare_3);
lcd.setCursor(0,1);
lcd.write(3);
lcd.createChar(4,girare_4);
lcd.setCursor(1,1);
lcd.write(4);
lcd.createChar(5,orologio_6);
lcd.setCursor(2,1);
lcd.write(5);
}
if(dtg >= intervallog){
t0h = millis();
aVal = digitalRead(pinA);
lcd.createChar(0,orologio_1);
lcd.setCursor(0,0);
lcd.write(0);
lcd.createChar(1,girare_1);
lcd.setCursor(1,0);
lcd.write(1);
lcd.createChar(2,orologio_3);
lcd.setCursor(2,0);
lcd.write(2);
lcd.createChar(3,rotellina_8);
lcd.setCursor(0,1);
lcd.write(3);
lcd.createChar(4,rotellina_9);
lcd.setCursor(1,1);
lcd.write(4);
lcd.createChar(5,orologio_6);
lcd.setCursor(2,1);
lcd.write(5);
}
if(dth >= intervalloh){
t0h = millis();
aVal = digitalRead(pinA);
lcd.createChar(0,orologio_1);
lcd.setCursor(0,0);
lcd.write(0);
lcd.createChar(1,girare_1);
lcd.setCursor(1,0);
lcd.write(1);
lcd.createChar(2,girare_2);
lcd.setCursor(2,0);
lcd.write(2);
lcd.createChar(3,girare_3);
lcd.setCursor(0,1);
lcd.write(3);
lcd.createChar(4,girare_4);
lcd.setCursor(1,1);
lcd.write(4);
lcd.createChar(5,orologio_6);
lcd.setCursor(2,1);
lcd.write(5);
}
if(dti >= intervalloi){
t0i = millis();
aVal = digitalRead(pinA);
lcd.createChar(0,rotellina_10);
lcd.setCursor(0,0);
lcd.write(0);
lcd.createChar(1,rotellina_11);
lcd.setCursor(1,0);
lcd.write(1);
lcd.createChar(2,orologio_3);
lcd.setCursor(2,0);
lcd.write(2);
lcd.createChar(3,orologio_4);
lcd.setCursor(0,1);
lcd.write(3);
lcd.createChar(4,girare_4);
lcd.setCursor(1,1);
lcd.write(4);
lcd.createChar(5,orologio_6);
lcd.setCursor(2,1);
lcd.write(5);
}
}