Advertisement
Guest User

bis

a guest
Feb 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.43 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3.  
  4. LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3, POSITIVE);
  5. //LiquidCrystal_I2C lcd(0x3F,16,2,1);
  6.  
  7.  
  8. long altezza = 80;
  9. long larghezza = 80;
  10. long canalina = 12;
  11.  
  12. int conteggio=0;
  13.  
  14. int posizione = 0;
  15. bool pronto = false;
  16. bool eseguito = false;
  17. bool esegui = false;
  18. int pos = 0;
  19. int prog = 0; //Progresso totale scritto
  20. int bar_prog = 0; //Progress barra
  21. int minimo = 50;
  22. bool errore = false;
  23. bool completato = false;
  24.  
  25. bool pos1=true;
  26. bool pos2=false;
  27. bool pos3=false;
  28. int tot = 0;
  29.  
  30. volatile bool _imposta = false;
  31.  
  32. bool premuto2 = false;
  33. bool premuto3 = false;
  34. bool premuto4 = false;
  35. bool premuto1 = false;
  36. int led1 = 10;
  37. int led2 = 8;
  38.  
  39.  
  40. byte p1[8] = {
  41.   B11111,
  42.   B11110,
  43.   B11100,
  44.   B11001,
  45.   B10011,
  46.   B00111,
  47.   B01111,
  48.   B11111,
  49. };
  50.  
  51. byte p2[8] = {
  52.   B00000,
  53.   B01010,
  54.   B11011,
  55.   B11011,
  56.   B11011,
  57.   B11011,
  58.   B11011,
  59.   B11011,
  60. };
  61.  
  62. byte p3[8] = {
  63.   B11111,
  64.   B01111,
  65.   B00111,
  66.   B10011,
  67.   B11001,
  68.   B11100,
  69.   B11110,
  70.   B11111,
  71. };
  72.  
  73. byte p4[8] =
  74. {
  75.   B00000,
  76.   B00000,
  77.   B00000,
  78.   B00000,
  79.   B00001,
  80.   B00011,
  81.   B00111,
  82.   B01111,
  83. };
  84.  
  85. byte p5[8] =
  86. {
  87.   B00000,
  88.   B00100,
  89.   B01110,
  90.   B11111,
  91.   B11111,
  92.   B11111,
  93.   B11111,
  94.   B11111,
  95. };
  96.  
  97. byte p6[8] =
  98. {
  99.   B00000,
  100.   B00000,
  101.   B00000,
  102.   B00000,
  103.   B10000,
  104.   B11000,
  105.   B11100,
  106.   B11110,
  107. };
  108.  
  109. byte frecciaSX[8] =
  110. {
  111.   B00000,
  112.   B00100,
  113.   B01100,
  114.   B11111,
  115.   B11111,
  116.   B01100,
  117.   B00100,
  118.   B00000,
  119. };
  120.  
  121.  
  122. byte progresso[8] =
  123. {
  124.   B11111,
  125.   B11111,
  126.   B11111,
  127.   B11111,
  128.   B11111,
  129.   B11111,
  130.   B11111,
  131.   B11111,
  132. };
  133.  
  134.  
  135.   int leggere = 10;
  136.   int passo = 0;
  137.   int segue[9];
  138.  
  139.   int lettura1 = 10;
  140.   int leggere1 = 10;
  141.   int passo1 = 0;
  142.   int segue1[9];
  143.  
  144.   int lettura2;
  145.   int leggere2 = 10;
  146.   int passo2 = 0;
  147.   int segue2[9];
  148.  
  149.   int lettura3;
  150.   int leggere3 = 10;
  151.   int passo3 = 0;
  152.   int segue3[9];
  153.  
  154.  
  155. void setup()
  156. {
  157.  
  158.  
  159.    Serial.begin(9600);
  160.    
  161.    //Lettura tasti
  162.    pinMode(A0,INPUT);
  163.    pinMode(A1,INPUT);
  164.    pinMode(A2,INPUT);
  165.    pinMode(A3,INPUT);
  166.  
  167.    pinMode(A4,OUTPUT);
  168.    pinMode(A5,OUTPUT);
  169.    
  170.    pinMode(led1,OUTPUT);
  171.    pinMode(led2,OUTPUT);
  172.    
  173.    digitalWrite(A4,HIGH);
  174.    digitalWrite(A5,HIGH);
  175.    
  176.   //Creazione simboli
  177.   lcd.createChar(0, p1);
  178.   lcd.createChar(1, p2);
  179.   lcd.createChar(2, p3);
  180.   lcd.createChar(3, p4);
  181.   lcd.createChar(4, p5);
  182.   lcd.createChar(5, p6);
  183.   lcd.createChar(6,frecciaSX);
  184.   lcd.createChar(7,progresso);
  185.  
  186.  
  187.   lcd.begin(16,2);
  188.   lcd.backlight();
  189.   // put your setup code here, to run once:
  190.  
  191.   lcd.setCursor(0,0);
  192.  
  193.   //logo();
  194.  
  195.   lcd.setCursor(5,0);
  196.     lcd.print("MP Glass");
  197.     lcd.setCursor(5,1);
  198.     lcd.print("s.r.l.");
  199.    
  200.      delay(3000);
  201.     lcd.clear();
  202.  
  203.     lcd.setCursor(0,0);
  204.     lcd.print("inizializzazione");
  205.  
  206.     lcd.setCursor(0,1);
  207.     delay(500);
  208.     lcd.print(".");
  209.     delay(500);
  210.     lcd.print("..");
  211.      delay(500);
  212.     lcd.print("...");
  213.      delay(500);
  214.     lcd.print("....");
  215.      delay(500);
  216.     lcd.print(".....");
  217.  
  218.     delay(200);
  219.    
  220.     resettainput();
  221.    
  222.     imposta();  
  223.  
  224.    //   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;
  225.  
  226.      
  227. }
  228.  
  229.  
  230.  
  231.  
  232.  
  233. void logo()
  234. {
  235.  
  236.   lcd.setCursor(0,1);
  237.   lcd.write(byte(0));
  238.   lcd.setCursor(1,1);
  239.   lcd.write(byte(1));
  240.   lcd.setCursor(2,1);
  241.   lcd.write(byte(2));
  242.   lcd.setCursor(0,0);
  243.   lcd.write(byte(3));
  244.   lcd.setCursor(1,0);
  245.   lcd.write(byte(4));
  246.   lcd.setCursor(2,0);
  247.   lcd.write(byte(5));
  248. }
  249.  
  250.  
  251. long prima;
  252. int attesaDebounce = 50;
  253.  
  254.  
  255. void imposta()
  256. {
  257.   lcd.clear();
  258.   lcd.setCursor(0,0);
  259.   lcd.print("H  x  L    MM");
  260.  
  261.   lcd.setCursor(0,1);
  262.  
  263.    lcd.print((uint8_t)altezza);
  264.  
  265.  
  266.   lcd.setCursor(6,1);
  267.   lcd.print((uint8_t)larghezza);
  268.  
  269.   lcd.setCursor(11,1);
  270.   lcd.print((uint8_t)canalina);
  271.  
  272.   _imposta = true;
  273.  
  274. }
  275.  
  276. int ultimaLettura = LOW;
  277. int pulsanteStato = LOW;
  278. int ledPin = 13;
  279. int ledStato = LOW;
  280. unsigned long ultimoTempoDebounce = 0;
  281. int lettura;
  282.  
  283.  
  284. void loop()
  285. {
  286.  Serial.begin(9600);
  287.  
  288.   //Settaggio misure
  289.   if(_imposta)
  290.   {
  291.    
  292.     if(posizione == 0)
  293.     {
  294.       lcd.setCursor(4,1);
  295.       lcd.print("<");
  296.      
  297.     }
  298.    
  299.    
  300.     if(posizione == 1)
  301.     {
  302.       lcd.setCursor(9,1);
  303.       lcd.print("<");
  304.     }
  305.    
  306.    
  307.   }
  308.  
  309.  
  310.  
  311.    
  312.   //controllo tasti
  313.   //lettura = analogRead(A0);
  314.  
  315.   //--------------------------
  316.   lettura = analogRead(A0);
  317.  
  318.   if(passo != leggere)
  319.   {
  320.      segue[passo] = lettura; passo++;    
  321.      
  322.   }
  323.  
  324.  
  325.   if(passo == leggere) { passo = 0; }
  326.  
  327.   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;};
  328.  
  329.  
  330.  
  331.   //-----------------------------------
  332.  
  333.   lettura1 = analogRead(A1);
  334.  
  335.   if(passo1 != leggere1)
  336.   {
  337.      segue1[passo1] = lettura1; passo1++;    
  338.      
  339.   }
  340.    if(passo1 == leggere1) { passo1 = 0; }
  341.  
  342.  
  343.  
  344.   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; }
  345.  
  346.  
  347.    //-----------------------------------
  348.    
  349.   //-----------------------------------
  350.  
  351.   lettura2 = analogRead(A2);
  352.  
  353.   if(passo2 != leggere2)
  354.   {
  355.      segue2[passo2] = lettura2; passo2++;    
  356.      
  357.   }
  358.    if(passo2 == leggere2) { passo2 = 0; }
  359.  
  360.  
  361.  
  362.   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; }
  363.  
  364.  
  365.    //-----------------------------------
  366.  
  367.   lettura3 = analogRead(A3);
  368.  
  369.   if(passo3 != leggere3)
  370.   {
  371.      segue3[passo3] = lettura3; passo3++;    
  372.      
  373.   }
  374.    if(passo3 == leggere3) { passo3 = 0; }
  375.  
  376.  
  377.   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; }
  378.  
  379.  //--------------------
  380.  
  381.    if(premuto1)
  382.    {
  383.    
  384.     if(posizione == 2) { posizione = 0; }
  385.     resettainput();
  386.      posizione++;
  387.      premuto1= false;
  388.      imposta(); delay(600);
  389.      
  390.    }
  391.    
  392.    //Pulsante 2 premuto
  393.    if(premuto2)
  394.    {
  395.    
  396.      if(posizione == 0) { resettainput(); altezza+=10; premuto2 = false; imposta(); delay(600); }
  397.      if(posizione == 1) { resettainput(); larghezza+=10; premuto2 = false; imposta(); delay(600); }
  398.      if(posizione == 2) { resettainput(); canalina++; premuto2 = false; imposta(); delay(600); }
  399.    }
  400.    
  401.    if(premuto3)
  402.    {
  403.      
  404.     if(posizione == 0) { resettainput(); altezza-=10; premuto3 = false;  imposta(); delay(600);}
  405.     if(posizione == 1) { resettainput(); larghezza-=10; premuto3 = false; imposta(); delay(600); }
  406.     if(posizione == 2) { resettainput(); canalina--; premuto3=false; imposta(); delay(600); }
  407.    }
  408.    
  409.    
  410.    
  411.    if(premuto4)
  412.    {
  413.    
  414.      lcd.clear();
  415.      lcd.setCursor(0,0);
  416.       lcd.print("AVVIO!");
  417.       digitalWrite(led1,HIGH);
  418.       digitalWrite(A4,LOW);
  419.      delay(5000);
  420.      
  421.    }
  422.    
  423.    //if(altezza > 240) { altezza = 10; }
  424.    //if(larghezza < 240) { larghezza = 10; }
  425.    
  426.  
  427. }
  428.  
  429.  
  430. void resettainput()
  431. {
  432.   segue[0] = -1;
  433.   segue[1] = -1;
  434.   segue[2] = -1;
  435.   segue[3] = -1;
  436.   segue[4] = -1;
  437.   segue[5] = -1;
  438.   segue[6] = -1;
  439.   segue[7] = -1;
  440.   segue[8] = -1;
  441.   segue[9] = -1;
  442.  
  443.   segue1[0] = -1;
  444.   segue1[1] = -1;
  445.   segue1[2] = -1;
  446.   segue1[3] = -1;
  447.   segue1[4] = -1;
  448.   segue1[5] = -1;
  449.   segue1[6] = -1;
  450.   segue1[7] = -1;
  451.   segue1[8] = -1;
  452.   segue1[9] = -1;
  453.  
  454.    
  455.   segue2[0] = -1;
  456.   segue2[1] = -1;
  457.   segue2[2] = -1;
  458.   segue2[3] = -1;
  459.   segue2[4] = -1;
  460.   segue2[5] = -1;
  461.   segue2[6] = -1;
  462.   segue2[7] = -1;
  463.   segue2[8] = -1;
  464.   segue2[9] = -1;  
  465.  
  466.   segue3[0] = -1;
  467.   segue3[1] = -1;
  468.   segue3[2] = -1;
  469.   segue3[3] = -1;
  470.   segue3[4] = -1;
  471.   segue3[5] = -1;
  472.   segue3[6] = -1;
  473.   segue3[7] = -1;
  474.   segue3[8] = -1;
  475.   segue3[9] = -1;
  476.  
  477. }
  478.  
  479. void avanzamento()
  480. {
  481.   tot = altezza + larghezza;
  482.  
  483.   delay(tot + (canalina*2));
  484.   prog++;
  485.  
  486.   if(prog == 10) { bar_prog++;}
  487.   if(prog == 20) { bar_prog++;}
  488.   if(prog == 30) { bar_prog++; }
  489.   if(prog == 40) { bar_prog++; }
  490.   if(prog == 50) { bar_prog++; }
  491.   if(prog == 60) { bar_prog++; }
  492.   if(prog == 70) { bar_prog++; }
  493.   if(prog == 80) { bar_prog++; }
  494.   if(prog == 90) { bar_prog++; }
  495.   if(prog == 100) { bar_prog++; }
  496.  
  497.   if(prog == 100) { esegui=false; completato = true;}
  498.  
  499.  
  500. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement