Guest User

twenty-four

a guest
Jun 10th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2.  
  3. //declaracion de variables
  4.  
  5. int RS = 12, EN = 11, D4 = 5, D5 = 4, D6 = 3, D7 = 2;
  6. LiquidCrystal LCD(RS, EN, D4, D5, D6, D7);
  7.  
  8. char cadena[16];
  9. int seg = 0;
  10. int mins = 0;
  11. int hor = 0;
  12.  
  13. bool p1 = false;
  14. bool veinticuatro = false;
  15.  
  16. void setup() {
  17.     LCD.begin(16,2);
  18.     pinMode(7, INPUT);
  19.     pinMode(8, INPUT);
  20.     pinMode(9, INPUT);
  21.     pinMode(10, INPUT);
  22. }
  23.  
  24. void loop() {
  25.     LCD.setCursor(0, 0);
  26.  
  27.     if (veinticuatro) {
  28.         LCD.print("Reloj 24hrs");
  29.     } else {
  30.         LCD.print("Reloj 12hrs");
  31.     }
  32.  
  33.     delay(1);
  34.     seg++;
  35.  
  36.     if (seg > 59) {
  37.         seg = 0;
  38.         mins++;
  39.     }
  40.  
  41.     if (mins > 59) {
  42.         mins = 0;
  43.         hor++;
  44.     }
  45.  
  46.     if (veinticuatro) {
  47.         if (hor > 24) { // <---- should be 23?
  48.             hor = 0;
  49.         }
  50.     } else {
  51.         if (hor > 11) {
  52.             hor = 0;
  53.         }
  54.     }
  55.  
  56.     sprintf(cadena, "%02d:%02d:%02d ", hor, mins, seg);
  57.     LCD.setCursor(0, 1);
  58.     LCD.print(cadena);
  59.  
  60.     if (digitalRead(7)) {
  61.         p1 = !p1;
  62.     }
  63.  
  64.     if (p1) {
  65.         veinticuatro = false;
  66.     } else {
  67.         veinticuatro = true;
  68.     }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment