Advertisement
Alexislls

Untitled

Oct 23rd, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #include <LiquidCrystal.h> //Importamos la librería LiquidCrystal
  2.  
  3. LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Creamos la variable y establecemos los pines del display
  4. byte fechad[8] = {
  5. B00001,
  6. B00011,
  7. B00111,
  8. B01111,
  9. B01111,
  10. B00111,
  11. B00011,
  12. B00001
  13. };
  14. byte fechai[8] = {
  15. B10000,
  16. B11000,
  17. B11100,
  18. B11110,
  19. B11110,
  20. B11100,
  21. B11000,
  22. B10000
  23. };
  24. byte cursorLCD[8] = {B00000, B00000, B00110, B01111, B01111, B00110, B00000};
  25.  
  26. int seg = 57;
  27. int min = 59;
  28. int hour = 23;
  29.  
  30. int formatoTime = 1;
  31.  
  32.  
  33. void setup()
  34. {
  35.  
  36. lcd.createChar(0, fechad);
  37. lcd.createChar(1, fechai);
  38. lcd.createChar(2, cursorLCD);
  39. lcd.begin(16, 2); //Inicializamos el display configurando 16 columnas por 2 filas
  40. lcd.setCursor(0,0); //Ponemos el cursor en la primera fila a la izquierda
  41. lcd.print("Inicializando..."); //Imprimimos un mensaje inicial
  42. delay(1000); //Esperamos 2 segundos
  43. lcd.clear(); //Borramos lo que pone la pantalla
  44. }
  45.  
  46. void loop()
  47. {
  48.  
  49. seg++;
  50. if(seg==60){
  51. min++;
  52. seg = 0;
  53. }
  54. if(min==60){
  55. hour++;
  56. min = 0;
  57. }
  58. if(hour==24){
  59.  
  60. hour = 0;
  61. }
  62.  
  63. mostrarHora();
  64.  
  65. delay(50);
  66. lcd.clear();
  67.  
  68. }
  69.  
  70. void mostrarHora(){
  71. if(formatoTime == 0){/* 12 horas*/
  72. lcd.setCursor(0,0);
  73.  
  74. int bandera = 1;
  75. int hora = hour;
  76. if(hora>12){
  77. bandera =1;
  78. hora = hora -12;
  79. }
  80. String sM="AM ";
  81. String sHora = String(hora);
  82. String sMin = String(min);
  83. String sSeg = String(seg);
  84. if(hora<10){sHora="0"+String(hora);}
  85. if(min<10){sMin="0"+String(min);}
  86. if(seg<10){sSeg="0"+String(seg);}
  87. if(bandera==1){
  88. sM="PM ";
  89. }
  90. String cadena1 = " "+sHora+":"+sMin+":"+sSeg+" "+sM;
  91. lcd.print(cadena1);
  92. }else{ /* 24 horas*/
  93. lcd.setCursor(0,0);
  94. String sHora = String(hour);
  95. String sMin = String(min);
  96. String sSeg = String(seg);
  97. if(hour<10){sHora="0"+String(hour);}
  98. if(min<10){sMin="0"+String(min);}
  99. if(seg<10){sSeg="0"+String(seg);}
  100.  
  101. String cadena1 = " "+sHora+":"+sMin+":"+sSeg+" ";
  102. lcd.print(cadena1);
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement