Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- //declaracion de variables
- int RS = 12, EN = 11, D4 = 5, D5 = 4, D6 = 3, D7 = 2;
- LiquidCrystal LCD(RS, EN, D4, D5, D6, D7);
- char cadena[16];
- int seg = 0;
- int mins = 0;
- int hor = 0;
- bool p1 = false;
- bool veinticuatro = false;
- void setup() {
- LCD.begin(16,2);
- pinMode(7, INPUT);
- pinMode(8, INPUT);
- pinMode(9, INPUT);
- pinMode(10, INPUT);
- }
- void loop() {
- LCD.setCursor(0, 0);
- if (veinticuatro) {
- LCD.print("Reloj 24hrs");
- } else {
- LCD.print("Reloj 12hrs");
- }
- delay(1);
- seg++;
- if (seg > 59) {
- seg = 0;
- mins++;
- }
- if (mins > 59) {
- mins = 0;
- hor++;
- }
- if (veinticuatro) {
- if (hor > 24) { // <---- should be 23?
- hor = 0;
- }
- } else {
- if (hor > 11) {
- hor = 0;
- }
- }
- sprintf(cadena, "%02d:%02d:%02d ", hor, mins, seg);
- LCD.setCursor(0, 1);
- LCD.print(cadena);
- if (digitalRead(7)) {
- p1 = !p1;
- }
- if (p1) {
- veinticuatro = false;
- } else {
- veinticuatro = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment