Advertisement
AlexShu

DS1302 Real Time Clock /w Arduino

Sep 27th, 2015
9,940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. \*
  2. Required library - http://www.rinkydinkelectronics.com/library.php?id=5
  3. Blog Post - http://overskill.alexshu.com/ds1302-real-time-clock-w-arduino/
  4. */
  5.  
  6. #include <DS1302.h>
  7.  
  8. // Init the DS1302
  9. DS1302 rtc(2, 3, 4);    // Change the pins here if you want
  10.  
  11. void setup()
  12. {
  13. // Set the clock to run-mode, and disable the write protection
  14. rtc.halt(false);
  15. rtc.writeProtect(false);
  16.  
  17. // Setup Serial connection
  18. Serial.begin(9600);
  19.  
  20. // The following lines can be commented out to use the values already stored in the DS1302
  21. // Once you flash the arduino with the correct time.
  22.  
  23. rtc.setDOW(FRIDAY); // Set Day-of-Week to FRIDAY
  24. rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
  25. rtc.setDate(6, 8, 2010); // Set the date to August 6th, 2010
  26. }
  27.  
  28. void loop()
  29. {
  30. // Send Day-of-Week
  31. Serial.print(rtc.getDOWStr());
  32. Serial.print(" ");
  33.  
  34. // Send date
  35. Serial.print(rtc.getDateStr());
  36. Serial.print(" -- ");
  37.  
  38. // Send time
  39. Serial.println(rtc.getTimeStr());
  40.  
  41. // Wait one second before repeating :)
  42. delay (1000);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement