Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h> //Importamos la librería LiquidCrystal
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Creamos la variable y establecemos los pines del display
- byte fechad[8] = {
- B00001,
- B00011,
- B00111,
- B01111,
- B01111,
- B00111,
- B00011,
- B00001
- };
- byte fechai[8] = {
- B10000,
- B11000,
- B11100,
- B11110,
- B11110,
- B11100,
- B11000,
- B10000
- };
- byte cursorLCD[8] = {B00000, B00000, B00110, B01111, B01111, B00110, B00000};
- int seg = 57;
- int min = 59;
- int hour = 23;
- int formatoTime = 1;
- void setup()
- {
- lcd.createChar(0, fechad);
- lcd.createChar(1, fechai);
- lcd.createChar(2, cursorLCD);
- lcd.begin(16, 2); //Inicializamos el display configurando 16 columnas por 2 filas
- lcd.setCursor(0,0); //Ponemos el cursor en la primera fila a la izquierda
- lcd.print("Inicializando..."); //Imprimimos un mensaje inicial
- delay(1000); //Esperamos 2 segundos
- lcd.clear(); //Borramos lo que pone la pantalla
- }
- void loop()
- {
- seg++;
- if(seg==60){
- min++;
- seg = 0;
- }
- if(min==60){
- hour++;
- min = 0;
- }
- if(hour==24){
- hour = 0;
- }
- mostrarHora();
- delay(50);
- lcd.clear();
- }
- void mostrarHora(){
- if(formatoTime == 0){/* 12 horas*/
- lcd.setCursor(0,0);
- int bandera = 1;
- int hora = hour;
- if(hora>12){
- bandera =1;
- hora = hora -12;
- }
- String sM="AM ";
- String sHora = String(hora);
- String sMin = String(min);
- String sSeg = String(seg);
- if(hora<10){sHora="0"+String(hora);}
- if(min<10){sMin="0"+String(min);}
- if(seg<10){sSeg="0"+String(seg);}
- if(bandera==1){
- sM="PM ";
- }
- String cadena1 = " "+sHora+":"+sMin+":"+sSeg+" "+sM;
- lcd.print(cadena1);
- }else{ /* 24 horas*/
- lcd.setCursor(0,0);
- String sHora = String(hour);
- String sMin = String(min);
- String sSeg = String(seg);
- if(hour<10){sHora="0"+String(hour);}
- if(min<10){sMin="0"+String(min);}
- if(seg<10){sSeg="0"+String(seg);}
- String cadena1 = " "+sHora+":"+sMin+":"+sSeg+" ";
- lcd.print(cadena1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement