// Program: Date and time with RTC DS1302 module // Amendment and adaptation: Arduino and Cia // // Based on the original program Krodal and virtuabotixRTC library // Load the virtuabotixRTC library #include "virtuabotixRTC.h" // Determine the pins connected to the module // myRTC (clock, data, RST) virtuabotixRTC myRTC (6, 7, 8); void setup () { Serial.begin (9600); // date and time of initial Information // After to set the entire information, comment the following line // (seconds, minutes, hours, day of week, day of month, month, year) myRTC.setDS1302Time (0, 18, 23, 6, 31, 7, 2021); } void loop () { // Reads the information from the CI myRTC.updateTime (); // Print the details in serial monitor Serial.print ("Data "); // Call the routine that prints the day of the week imprime_dia_da_semana (myRTC.dayofweek); Serial.print (", "); Serial.print (myRTC.dayofmonth); Serial.print ("/"); Serial.print (myRTC.month); Serial.print ("/"); Serial.print (myRTC.year); Serial.print (""); Serial.print (" Time "); // Adds a 0 if the time value is <10 if (myRTC.hours <10) { Serial.print ("0"); } Serial.print (myRTC.hours); Serial.print (":"); // Adds a 0 if the value of the minutes is <10 if (myRTC.minutes <10) { Serial.print ("0"); } Serial.print (myRTC.minutes); Serial.print (":"); // Adds a 0 if the value of the latter is <10 if (myRTC.seconds <10) { Serial.print ("0"); } Serial.println (myRTC.seconds); delay (1000); } void imprime_dia_da_semana (int day) { switch (day) { case 1: Serial.print ("Sunday"); break; case 2: Serial.print ("Second"); break; case 3: Serial.print ("Terca"); break; case 4: Serial.print ("Wednesday"); break; case 5: Serial.print ("Quinta"); break; case 6: Serial.print ("Friday"); break; case 7: Serial.print ("Saturday"); break; } }