Advertisement
RuiViana

L_V03

May 30th, 2019
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.97 KB | None | 0 0
  1. ////link do video do projeto:https://www.youtube.com/watch?v=5uu6ctnZUPw
  2.  
  3. #include <Wire.h>
  4. #include <LiquidCrystal_I2C.h>
  5. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
  6.  
  7. #define bot1 2
  8. #define Led1 3
  9. #define bot2 4
  10. #define Led2 5
  11. #define bot3 6
  12. #define Led3 7
  13.  
  14. unsigned long seg1;
  15. unsigned long seg2;
  16. unsigned long seg3;
  17.  
  18. int segundos1 = 20; //segundos do botão botão 1
  19. int segundos2 = 15; //segundos do botão botão 2
  20. int segundos3 = 10; //segundos do botão botão 3
  21. int entrada1 = 0;
  22. int entrada2 = 0;
  23. int entrada3 = 0;
  24. int flag1 = 0;
  25. int flag2 = 0;
  26. int flag3 = 0;
  27.  
  28. void setup() {
  29.  
  30.   lcd.begin(16, 2);
  31.   lcd.setCursor(0, 0);
  32.   lcd.print("Temporizador");
  33.   lcd.setCursor(0, 1);
  34.   lcd.print("");
  35.   delay(2000);
  36.  
  37.   pinMode(bot1, INPUT);  //botão 1
  38.   pinMode(bot2, INPUT);  //botão 2
  39.   pinMode(bot3, INPUT);  //botão 3
  40.   pinMode(Led1, OUTPUT); //led 1
  41.   pinMode(Led2, OUTPUT); //led 2
  42.   pinMode(Led3, OUTPUT); //led 3
  43. }
  44. //------------------------------------------------------------
  45. void loop() {
  46.   entrada1 = digitalRead(bot1);     //botão 1
  47.   if (entrada1 == HIGH ) {
  48.     flag1 = 1;
  49.     seg1 = millis();
  50.   }
  51.   entrada2 = digitalRead(bot2);     //botão 2
  52.   if (entrada2 == HIGH ) {
  53.     flag2 = 1;
  54.     seg2 = millis();
  55.   }
  56.   entrada3 = digitalRead(bot3);     //botão 3
  57.   if (entrada3 == HIGH ) {
  58.     flag3 = 1;
  59.     seg3 = millis();
  60.   }
  61.  
  62.   if (flag1 == 1) {
  63.     digitalWrite(Led1, HIGH);       //acende o led ao pressionar o botão 1
  64.     if (millis() - seg1 >= 1000)
  65.     {
  66.       seg1 = millis();
  67.       segundos1--;
  68.       lcd.setCursor(5, 0);
  69.       if (segundos1 < 10) {
  70.         lcd.print("0");
  71.       }
  72.       lcd.print(segundos1);
  73.     }
  74.     if (segundos1 == 0) {             //Quando zerar o tempo1
  75.       segundos1 = 20;
  76.       flag1 = 0;
  77.       digitalWrite(Led1, LOW);
  78.     }
  79.   }
  80.   if (flag2 == 1) {
  81.     digitalWrite(Led2, HIGH);         //acende o led ao pressionar o botão 2
  82.     if (millis() - seg2 >= 1000)
  83.     {
  84.       seg2 = millis();
  85.       segundos2--;
  86.       lcd.setCursor(13, 0);
  87.       if (segundos2 < 10) {
  88.         lcd.print("0");
  89.       }
  90.       lcd.print(segundos2);
  91.     }
  92.     if (segundos2 == 0) {           //Quando zerar o tempo2
  93.       segundos2 = 15;
  94.       flag2 = 0;
  95.       digitalWrite(Led2, LOW);
  96.     }
  97.   }
  98.   if (flag3 == 1) {
  99.     digitalWrite(Led3, HIGH);     //acende o led ao pressionar o botão 3
  100.     if (millis() - seg3 >= 1000)
  101.     {
  102.       seg3 = millis();
  103.       segundos3--;
  104.       lcd.setCursor(5, 1);
  105.       if (segundos3 < 10) {
  106.         lcd.print("0");
  107.       }
  108.       lcd.print(segundos3);
  109.     }
  110.     if (segundos3 == 0) {         //Quando zerar o tempo3
  111.       segundos3 = 10;
  112.       flag3 = 0;
  113.       digitalWrite(Led3, LOW);
  114.     }
  115.   }
  116.   if (flag1 == 0 and flag2 == 0 and flag3 == 0)
  117.   {
  118.     lcd.clear();
  119.     lcd.setCursor(0, 0);
  120.     lcd.print("T1 = 20 T2 = 15");     // tela de 3 opções de cronometro
  121.     lcd.setCursor(0, 1);
  122.     lcd.print("T3 = 10");
  123.     delay(200);
  124.   }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement