Advertisement
Guest User

Read time and write to the LCD

a guest
Apr 1st, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #include <Wire.h>
  2. //#include <LiquidCrystal_I2C.h>
  3. //LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // initializes the LCM1602 IIC V1 (LCD module)
  4. // 0x27 is the I2C address. This address might be different.
  5. #include <LiquidCrystal.h>
  6.  
  7. #include <ThreeWire.h>
  8. #include <RtcDS1302.h>
  9.  
  10. ThreeWire myWire(12,10,8); // IO, SCLK, CE
  11. RtcDS1302<ThreeWire> Rtc(myWire);
  12.  
  13. LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
  14.  
  15. void setup() {
  16. lcd.begin(16, 2);
  17. lcd.setCursor(0,0);
  18. lcd.write("test 1 2 3");
  19.  
  20. #define countof(a) (sizeof(a) / sizeof(a[0]))
  21. Rtc.Begin();
  22. RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
  23. Rtc.SetDateTime(compiled);
  24.  
  25.  
  26. // lcd.begin(16, 2); // begins connection to the LCD module
  27. // lcd.backlight(); // turns on the backlight
  28. Serial.begin(9600);
  29. }
  30.  
  31.  
  32. void loop() {
  33. // value_A0 = analogRead(IN_A0); // reads the analog input from the IR distance sensor
  34. // value_D0 = digitalRead(IN_D0);// reads the digital input from the IR distance sensor
  35.  
  36. RtcDateTime now = Rtc.GetDateTime();
  37.  
  38. printDateTime(now);
  39.  
  40. // char buffer[5] = "";
  41. // sprintf(buffer, "A0 = %04d", val0);
  42.  
  43. // Serial.println(value_A0);
  44. // Serial.println("digital " + value_D0);
  45. // Serial.println(value_A0,value_D0);
  46.  
  47. Serial.print("test");
  48. // lcd.setCursor(0, 0); // sets the cursor of the LCD module to the first line
  49. // lcd.print("A0:");
  50. // lcd.setCursor(3, 0); // sets the cursor of the LCD module to the fourth character
  51. // lcd.print(value_A0); // prints analog value on the LCD module
  52. //
  53. // lcd.setCursor(0, 1); // sets the cursor of the LCD module to the first line
  54. // lcd.print("D0:");
  55. // lcd.setCursor(3, 1); // sets the cursor of the LCD module to the fourth character
  56. // lcd.print(value_D0); // prints digital value on the LCD module
  57.  
  58. delay(1000);
  59.  
  60.  
  61. }
  62.  
  63. void printDateTime(const RtcDateTime& dt)
  64. {
  65. char datestring[11];
  66. char timestring[9];
  67.  
  68. snprintf_P(datestring,
  69. countof(datestring),
  70. PSTR("%02u/%02u/%04u"),
  71. dt.Month(),
  72. dt.Day(),
  73. dt.Year());
  74. lcd.setCursor(0,0);
  75. lcd.print(datestring);
  76. snprintf_P(timestring,
  77. countof(timestring),
  78. PSTR("%02u:%02u:%02u"),
  79. dt.Hour(),
  80. dt.Minute(),
  81. dt.Second() );
  82. lcd.setCursor(0,1);
  83. lcd.print(timestring);
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement