Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <virtuabotixRTC.h>
- int num;
- char* diaSem[7]={"Do", "Lu", "Ma", "Mi", "Ju", "Vi", "Sa"};
- char* amPM[2]={" AM", " PM"};
- byte posA;
- byte posB;
- int wA, wB, wC, wD, wE, wF, wG, wN, wS, numSem;
- //Inciando el RTC y el LCD
- virtuabotixRTC RTC(6, 7, 8);
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- void setup() {
- lcd.begin();
- lcd.backlight();
- //RTC.setDS1302Time(00, 39, 23, 5, 15, 4, 2016); //Ajuste inicial del reloj ss:mm:H L dd/mm/aaaa
- //Iniciar los pines de ajuste
- pinMode(9, INPUT);
- pinMode(10, INPUT);
- pinMode(11, INPUT);
- }
- void loop() {
- RTC.updateTime();
- imprimirSemana();
- imprimirDMA();
- imprimirDiaSem();
- imprimirHora();
- verificarAjuste();
- }
- void imprimirSemana(){
- if (RTC.month < 3) calculoSemEneMar();
- else calculoSemAbrDic();
- calculoSem();
- lcd.setCursor(1, 0);
- lcd.print("W");
- lcd.print(numSem);
- }
- void imprimirDMA(){
- num = RTC.dayofmonth;
- lcd.setCursor(5, 0);
- if (num < 10){
- lcd.print("0");
- lcd.print(num);
- }
- else lcd.print(num);
- lcd.print("/");
- num = RTC.month;
- if (num < 10){
- lcd.print("0");
- lcd.print(num);
- }
- else lcd.print(num);
- lcd.print("/");
- num = RTC.year;
- lcd.print(num);
- }
- void imprimirDiaSem(){
- lcd.setCursor(1, 1);
- lcd.print(diaSem[RTC.dayofweek]);
- lcd.print(" ");
- }
- void imprimirHora(){
- lcd.setCursor(4, 1);
- num = RTC.hours;
- if (num > 12) num = num - 12;
- if (num == 0) num = 12;
- if (num < 10) lcd.print("0");
- lcd.print(num);
- lcd.print(":");
- num = RTC.minutes;
- if (num < 10) lcd.print("0");
- lcd.print(num);
- lcd.print(":");
- num = RTC.seconds;
- if (num < 10) lcd.print("0");
- lcd.print(num);
- if (RTC.hours < 12) num = 0;
- if (RTC.hours > 11) num = 1;
- lcd.print(amPM[num]);
- }
- void calculoSemEneMar(){
- wA = RTC.year;
- wB = ((wA/4) - (wA/100) + (wA/400));
- wC = (((wA-1)/4) - ((wA-1)/100) + ((wA-1)/400));
- wS = wB - wC;
- wE = 0;
- wF = ((RTC.dayofmonth) - 1 + (31 * (RTC.month - 1)));
- }
- void calculoSemAbrDic(){
- wA = RTC.year;
- wB = ((wA/4) - (wA/100) + (wA/400));
- wC = (((wA-1)/4) - ((wA-1)/100) + ((wA-1)/400));
- wS = wB - wC;
- wE = wS + 1;
- wF = ((RTC.dayofmonth) + ((153 * (RTC.month - 3) + 2) / 5) + 58 + wS);
- }
- void calculoSem(){
- wG = ((wA + wB) % 7);
- wD = ((wF + wG - wE) % 7);
- wN = wF + 3 - wD;
- num = 364 + wS;
- if (wN < 0) numSem = (53 - ((wG - wS) / 5));
- else if (wN > num) numSem = 1;
- else numSem = ((wN / 7) + 1);
- }
- void verificarAjuste(){
- if (digitalRead(9) == HIGH) {
- obtenerVariables();
- num = RTC.seconds + 1;
- if (num == 60) num = 0;
- RTC.setDS1302Time(num, wB, wC, wD, wE, wF, wG); //Ajuste inicial del reloj ss:mm:H L dd/mm/aaaa
- }
- if (digitalRead(10) == HIGH) {
- obtenerVariables();
- num = RTC.minutes + 1;
- if (num == 60) num = 0;
- RTC.setDS1302Time(wA, num, wC, wD, wE, wF, wG); //Ajuste inicial del reloj ss:mm:H L dd/mm/aaaa
- }
- if (digitalRead(11) == HIGH) {
- obtenerVariables();
- num = RTC.hours + 1;
- if (num == 24) num = 0;
- RTC.setDS1302Time(wA, wB, num, wD, wE, wF, wG); //Ajuste inicial del reloj ss:mm:H L dd/mm/aaaa
- limpiarPantalla();
- }
- }
- void obtenerVariables(){
- wA = RTC.seconds;
- wB = RTC.minutes;
- wC = RTC.hours;
- wD = RTC.dayofweek;
- wE = RTC.dayofmonth;
- wF = RTC.month;
- wG = RTC.year;
- }
- void limpiarPantalla(){
- lcd.setCursor(0, 0);
- lcd.print(" ");
- lcd.print(" ");
- }
Advertisement
Add Comment
Please, Sign In to add comment