Advertisement
nikolas77

compte a rebours lcd

Aug 12th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <LiquidCrystal_I2C.h>
  2.  
  3. LiquidCrystal_I2C lcd1(0x26,20,4);
  4.  
  5. const int BP = 7;
  6. int BPstate = 0;
  7.  
  8. int time;
  9. int heure;
  10. int minute;
  11. int seconde;
  12.  
  13. long milliref;
  14.  
  15. void setup(){
  16.  
  17.     pinMode(BP, INPUT);
  18.     lcd1.init();
  19.     lcd1.backlight();
  20.  
  21.     heure = 0;
  22.     minute = 1;
  23.     seconde = 0;
  24.     time = (seconde + (60 * minute) + (3600 * heure));
  25. }
  26. void loop()    {  
  27.        
  28.     BPstate = digitalRead(BP);
  29.     lcd1.setCursor(1, 0);
  30.     lcd1.print("                ");
  31.    
  32.     lcd1.setCursor(3, 0);
  33.     lcd1.print("En Attente");
  34.     delay(10);
  35.     lcd1.setCursor(0, 1);
  36.     lcd1.print("                ");
  37.  
  38. if (BPstate == HIGH) {    
  39.         milliref = millis();
  40.         while (time > 1) {
  41.             if (millis() > (milliref + 1000)) {
  42.                 seconde = seconde - 1;
  43.                 time = time - 1;
  44.                 milliref = milliref + 1000;  
  45.             }
  46.             if (minute > 0) {
  47.                 if (seconde < 0) {
  48.                     minute--;
  49.                     seconde = 59;
  50.                 }
  51.             }
  52.             if (heure > 0) {
  53.                 if (minute <= 0) {
  54.                     if (time == 3600 * heure - 1) {
  55.                         heure--;
  56.                         minute = 59;
  57.                         seconde = 59;
  58.                     }
  59.                 }    
  60.             }
  61.             Display();
  62.             delay(980);
  63.         }
  64.     }
  65. }
  66. void Display() {
  67.  
  68.     lcd1.setCursor(1, 0);
  69.     lcd1.print("Temps Restant:");
  70.     lcd1.setCursor(1, 0);
  71.     lcd1.setCursor(4, 1);                                
  72.     lcd1.print("00:00:00");
  73.    
  74.     if (heure >= 10) {
  75.         lcd1.setCursor(4, 1);
  76.     }
  77.     else{
  78.         lcd1.setCursor(5, 1);
  79.     }
  80.         lcd1.print(heure);
  81.    
  82.     if (minute >= 10){
  83.             lcd1.setCursor(7, 1);
  84.     }
  85.     else {
  86.         lcd1.setCursor(8, 1);
  87.     }
  88.     lcd1.print(minute);
  89.    
  90.     if (seconde >= 10){
  91.         lcd1.setCursor(10, 1);
  92.     }
  93.     else {
  94.         lcd1.setCursor(11, 1);
  95.     }
  96.     lcd1.print(seconde);
  97.    
  98.     if (time <= 0){
  99.     }
  100.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement