Advertisement
AlexShu

DS1302 Real Time Clock and 12864 LCD /w Arduino

Sep 27th, 2015
9,822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. /*
  2. Required libraries: http://www.rinkydinkelectronics.com/library.php?id=5
  3.             https://code.google.com/p/u8glib/
  4. Blog Post:      http://overskill.alexshu.com/ds1302-real-time-clock-w-arduino/
  5. */
  6.  
  7. #include "U8glib.h"
  8. #include <DS1302.h>
  9. DS1302 rtc(2, 3, 4);
  10. U8GLIB_ST7920_128X64 u8g(13, 11, 12, U8G_PIN_NONE);
  11.  
  12. void draw(void) {
  13. u8g.setFont(u8g_font_04b_03);
  14. u8g.drawStr( 20, 10, "AquaTank Control V2");
  15. u8g.drawStr( 48,20, rtc.getTimeStr());
  16. u8g.drawStr( 40,30, rtc.getDOWStr());
  17. u8g.drawStr( 43,40, rtc.getDateStr());
  18. u8g.drawStr( 17,55, "DS1302 Real Time Clock");
  19. }
  20.  
  21. void setup(void) {
  22. rtc.halt(false);
  23. rtc.writeProtect(false);
  24.  
  25. // rtc.setDOW(WEDNESDAY); // Set Day-of-Week to FRIDAY
  26. // rtc.setTime(11, 40, 0); // Set the time to 12:00:00 (24hr format)
  27. // rtc.setDate(9, 4, 2014); // Set the date to August 6th, 2010
  28.  
  29. // assign default color value
  30. if ( u8g.getMode() == U8G_MODE_R3G3B2 )
  31. u8g.setColorIndex(255); // white
  32. else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
  33. u8g.setColorIndex(3); // max intensity
  34. else if ( u8g.getMode() == U8G_MODE_BW )
  35. u8g.setColorIndex(1); // pixel on
  36. }
  37.  
  38. void loop(void) {
  39. // picture loop
  40. u8g.firstPage();
  41. do {
  42. draw();
  43. } while( u8g.nextPage() );
  44.  
  45. // rebuild the picture after some delay
  46. delay(500);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement