Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3, POSITIVE);
- //LiquidCrystal_I2C lcd(0x3F,16,2,1);
- long altezza = 80;
- long larghezza = 80;
- long canalina = 12;
- int conteggio=0;
- int posizione = 0;
- bool pronto = false;
- bool eseguito = false;
- bool esegui = false;
- int pos = 0;
- int prog = 0; //Progresso totale scritto
- int bar_prog = 0; //Progress barra
- int minimo = 50;
- bool errore = false;
- bool completato = false;
- bool pos1=true;
- bool pos2=false;
- bool pos3=false;
- int tot = 0;
- volatile bool _imposta = false;
- bool premuto2 = false;
- bool premuto3 = false;
- bool premuto4 = false;
- bool premuto1 = false;
- int led1 = 10;
- int led2 = 8;
- byte p1[8] = {
- B11111,
- B11110,
- B11100,
- B11001,
- B10011,
- B00111,
- B01111,
- B11111,
- };
- byte p2[8] = {
- B00000,
- B01010,
- B11011,
- B11011,
- B11011,
- B11011,
- B11011,
- B11011,
- };
- byte p3[8] = {
- B11111,
- B01111,
- B00111,
- B10011,
- B11001,
- B11100,
- B11110,
- B11111,
- };
- byte p4[8] =
- {
- B00000,
- B00000,
- B00000,
- B00000,
- B00001,
- B00011,
- B00111,
- B01111,
- };
- byte p5[8] =
- {
- B00000,
- B00100,
- B01110,
- B11111,
- B11111,
- B11111,
- B11111,
- B11111,
- };
- byte p6[8] =
- {
- B00000,
- B00000,
- B00000,
- B00000,
- B10000,
- B11000,
- B11100,
- B11110,
- };
- byte frecciaSX[8] =
- {
- B00000,
- B00100,
- B01100,
- B11111,
- B11111,
- B01100,
- B00100,
- B00000,
- };
- byte progresso[8] =
- {
- B11111,
- B11111,
- B11111,
- B11111,
- B11111,
- B11111,
- B11111,
- B11111,
- };
- int leggere = 10;
- int passo = 0;
- int segue[9];
- int lettura1 = 10;
- int leggere1 = 10;
- int passo1 = 0;
- int segue1[9];
- int lettura2;
- int leggere2 = 10;
- int passo2 = 0;
- int segue2[9];
- int lettura3;
- int leggere3 = 10;
- int passo3 = 0;
- int segue3[9];
- void setup()
- {
- Serial.begin(9600);
- //Lettura tasti
- pinMode(A0,INPUT);
- pinMode(A1,INPUT);
- pinMode(A2,INPUT);
- pinMode(A3,INPUT);
- pinMode(A4,OUTPUT);
- pinMode(A5,OUTPUT);
- pinMode(led1,OUTPUT);
- pinMode(led2,OUTPUT);
- digitalWrite(A4,HIGH);
- digitalWrite(A5,HIGH);
- //Creazione simboli
- lcd.createChar(0, p1);
- lcd.createChar(1, p2);
- lcd.createChar(2, p3);
- lcd.createChar(3, p4);
- lcd.createChar(4, p5);
- lcd.createChar(5, p6);
- lcd.createChar(6,frecciaSX);
- lcd.createChar(7,progresso);
- lcd.begin(16,2);
- lcd.backlight();
- // put your setup code here, to run once:
- lcd.setCursor(0,0);
- //logo();
- lcd.setCursor(5,0);
- lcd.print("MP Glass");
- lcd.setCursor(5,1);
- lcd.print("s.r.l.");
- delay(3000);
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("inizializzazione");
- lcd.setCursor(0,1);
- delay(500);
- lcd.print(".");
- delay(500);
- lcd.print("..");
- delay(500);
- lcd.print("...");
- delay(500);
- lcd.print("....");
- delay(500);
- lcd.print(".....");
- delay(200);
- resettainput();
- imposta();
- // segue[0] = -1; segue[1] = -1; segue[2] = -1; segue[3] = -1; segue[4] = -1; segue[5] = -1; segue[6] = -1; segue[7] = -1; segue[8] = -1; segue[9] = -1;
- }
- void logo()
- {
- lcd.setCursor(0,1);
- lcd.write(byte(0));
- lcd.setCursor(1,1);
- lcd.write(byte(1));
- lcd.setCursor(2,1);
- lcd.write(byte(2));
- lcd.setCursor(0,0);
- lcd.write(byte(3));
- lcd.setCursor(1,0);
- lcd.write(byte(4));
- lcd.setCursor(2,0);
- lcd.write(byte(5));
- }
- long prima;
- int attesaDebounce = 50;
- void imposta()
- {
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("H x L MM");
- lcd.setCursor(0,1);
- lcd.print((uint8_t)altezza);
- lcd.setCursor(6,1);
- lcd.print((uint8_t)larghezza);
- lcd.setCursor(11,1);
- lcd.print((uint8_t)canalina);
- _imposta = true;
- }
- int ultimaLettura = LOW;
- int pulsanteStato = LOW;
- int ledPin = 13;
- int ledStato = LOW;
- unsigned long ultimoTempoDebounce = 0;
- int lettura;
- void loop()
- {
- Serial.begin(9600);
- //Settaggio misure
- if(_imposta)
- {
- if(posizione == 0)
- {
- lcd.setCursor(4,1);
- lcd.print("<");
- }
- if(posizione == 1)
- {
- lcd.setCursor(9,1);
- lcd.print("<");
- }
- }
- //controllo tasti
- //lettura = analogRead(A0);
- //--------------------------
- lettura = analogRead(A0);
- if(passo != leggere)
- {
- segue[passo] = lettura; passo++;
- }
- if(passo == leggere) { passo = 0; }
- if(segue[1] == 0 && segue[2] == 0 && segue[3] == 0 && segue[4] == 0 && segue[5] == 0 && segue[6] == 0 && segue[7] == 0 && segue[8] == 0) { premuto2=true;};
- //-----------------------------------
- lettura1 = analogRead(A1);
- if(passo1 != leggere1)
- {
- segue1[passo1] = lettura1; passo1++;
- }
- if(passo1 == leggere1) { passo1 = 0; }
- if(segue1[0] == 0 && segue1[1] == 0 && segue1[2] == 0 && segue1[3] == 0 && segue1[4] == 0 && segue1[5] == 0 && segue1[6] == 0 && segue1[7] == 0) { premuto1 = true; }
- //-----------------------------------
- //-----------------------------------
- lettura2 = analogRead(A2);
- if(passo2 != leggere2)
- {
- segue2[passo2] = lettura2; passo2++;
- }
- if(passo2 == leggere2) { passo2 = 0; }
- if(segue2[0] == 0 && segue2[1] == 0 && segue2[2] == 0 && segue2[3] == 0 && segue2[4] == 0 && segue2[5] == 0 && segue2[6] == 0 && segue2[7] == 0) { premuto3 = true; }
- //-----------------------------------
- lettura3 = analogRead(A3);
- if(passo3 != leggere3)
- {
- segue3[passo3] = lettura3; passo3++;
- }
- if(passo3 == leggere3) { passo3 = 0; }
- if(segue3[0] == 0 && segue3[1] == 0 && segue3[2] == 0 && segue3[3] == 0 && segue3[4] == 0 && segue3[5] == 0 && segue3[6] == 0 && segue3[7] == 0) { premuto4 = true; }
- //--------------------
- if(premuto1)
- {
- if(posizione == 2) { posizione = 0; }
- resettainput();
- posizione++;
- premuto1= false;
- imposta(); delay(600);
- }
- //Pulsante 2 premuto
- if(premuto2)
- {
- if(posizione == 0) { resettainput(); altezza+=10; premuto2 = false; imposta(); delay(600); }
- if(posizione == 1) { resettainput(); larghezza+=10; premuto2 = false; imposta(); delay(600); }
- if(posizione == 2) { resettainput(); canalina++; premuto2 = false; imposta(); delay(600); }
- }
- if(premuto3)
- {
- if(posizione == 0) { resettainput(); altezza-=10; premuto3 = false; imposta(); delay(600);}
- if(posizione == 1) { resettainput(); larghezza-=10; premuto3 = false; imposta(); delay(600); }
- if(posizione == 2) { resettainput(); canalina--; premuto3=false; imposta(); delay(600); }
- }
- if(premuto4)
- {
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("AVVIO!");
- digitalWrite(led1,HIGH);
- digitalWrite(A4,LOW);
- delay(5000);
- }
- //if(altezza > 240) { altezza = 10; }
- //if(larghezza < 240) { larghezza = 10; }
- }
- void resettainput()
- {
- segue[0] = -1;
- segue[1] = -1;
- segue[2] = -1;
- segue[3] = -1;
- segue[4] = -1;
- segue[5] = -1;
- segue[6] = -1;
- segue[7] = -1;
- segue[8] = -1;
- segue[9] = -1;
- segue1[0] = -1;
- segue1[1] = -1;
- segue1[2] = -1;
- segue1[3] = -1;
- segue1[4] = -1;
- segue1[5] = -1;
- segue1[6] = -1;
- segue1[7] = -1;
- segue1[8] = -1;
- segue1[9] = -1;
- segue2[0] = -1;
- segue2[1] = -1;
- segue2[2] = -1;
- segue2[3] = -1;
- segue2[4] = -1;
- segue2[5] = -1;
- segue2[6] = -1;
- segue2[7] = -1;
- segue2[8] = -1;
- segue2[9] = -1;
- segue3[0] = -1;
- segue3[1] = -1;
- segue3[2] = -1;
- segue3[3] = -1;
- segue3[4] = -1;
- segue3[5] = -1;
- segue3[6] = -1;
- segue3[7] = -1;
- segue3[8] = -1;
- segue3[9] = -1;
- }
- void avanzamento()
- {
- tot = altezza + larghezza;
- delay(tot + (canalina*2));
- prog++;
- if(prog == 10) { bar_prog++;}
- if(prog == 20) { bar_prog++;}
- if(prog == 30) { bar_prog++; }
- if(prog == 40) { bar_prog++; }
- if(prog == 50) { bar_prog++; }
- if(prog == 60) { bar_prog++; }
- if(prog == 70) { bar_prog++; }
- if(prog == 80) { bar_prog++; }
- if(prog == 90) { bar_prog++; }
- if(prog == 100) { bar_prog++; }
- if(prog == 100) { esegui=false; completato = true;}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement