Advertisement
RuiViana

HorarioDS1307.ino

Jan 13th, 2019
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <DS1307.h>               // Biblioteca DS1307  http://www.rinkydinkelectronics.com/library.php?id=34
  2. DS1307 rtc(SDA, SCL);             // Inicialize o DS1307
  3. char buffer[50];                  // Buffer de impressao
  4. //------------------------------------------------------------
  5. void setup()
  6. {
  7.   Serial.begin(115200);           // Inicialize o serial
  8.   rtc.begin();                    // Inicia o objeto RTC
  9.   rtc.halt(false);                // Define run-mode
  10. }
  11. //------------------------------------------------------------
  12. void loop()
  13. {
  14.   Time myclock = rtc.getTime();   // Instancia o objeto myClock e obtem o horario
  15.   int myHour = myclock.hour;      // Seleciona a hora
  16.   int myMin = myclock.min;        // Seleciona o minuto
  17.   int mySec = myclock.sec;        // Seleciona o segundo
  18.   //                                 Carrega no buffer e imprime o buffer
  19.   sprintf(buffer, " %02d:%02d:%02d", myHour, myMin, mySec),  Serial.println(buffer);
  20.   delay (1000);                   // Aguarda um segundo
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement