PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 satır
1.1KB

  1. #include <Wire.h>
  2. #include <TimeLib.h>
  3. #include <DS1307RTC.h>
  4. void setup() {
  5. Serial.begin(9600);
  6. while (!Serial) ; // wait for serial
  7. delay(200);
  8. Serial.println("DS1307RTC Read Test");
  9. Serial.println("-------------------");
  10. }
  11. void loop() {
  12. tmElements_t tm;
  13. if (RTC.read(tm)) {
  14. Serial.print("Ok, Time = ");
  15. print2digits(tm.Hour);
  16. Serial.write(':');
  17. print2digits(tm.Minute);
  18. Serial.write(':');
  19. print2digits(tm.Second);
  20. Serial.print(", Date (D/M/Y) = ");
  21. Serial.print(tm.Day);
  22. Serial.write('/');
  23. Serial.print(tm.Month);
  24. Serial.write('/');
  25. Serial.print(tmYearToCalendar(tm.Year));
  26. Serial.println();
  27. } else {
  28. if (RTC.chipPresent()) {
  29. Serial.println("The DS1307 is stopped. Please run the SetTime");
  30. Serial.println("example to initialize the time and begin running.");
  31. Serial.println();
  32. } else {
  33. Serial.println("DS1307 read error! Please check the circuitry.");
  34. Serial.println();
  35. }
  36. delay(9000);
  37. }
  38. delay(1000);
  39. }
  40. void print2digits(int number) {
  41. if (number >= 0 && number < 10) {
  42. Serial.write('0');
  43. }
  44. Serial.print(number);
  45. }