Guest User

Untitled

a guest
Mar 22nd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. //Set <DS1307RTC.h> to the top.
  2. //<DS1307RTC.h>を一番上に持ってくる
  3. #include <DS1307RTC.h>
  4. #include <Wire.h>
  5.  
  6. void setup() {
  7. Serial.begin(115200);
  8.  
  9. //set SDA and SCL port
  10. //SDA:21 SCL:22 is default
  11. //Some ports can not be used?
  12. //SDAとSCLを設定する。
  13. //SDA:21 SCL:22がデフォルトらしい
  14. //Wire.begin(SDA,SCL) でSDAとSCLの番号を変える
  15. //動くポート番号と動かないポート番号がある?
  16. Wire.begin(21,22);
  17. }
  18.  
  19. void loop() {
  20. tmElements_t tm;
  21.  
  22. if (RTC.read(tm)) {
  23. Serial.print("Ok, Time = ");
  24. print2digits(tm.Hour);
  25. Serial.write(':');
  26. print2digits(tm.Minute);
  27. Serial.write(':');
  28. print2digits(tm.Second);
  29. Serial.print(", Date (D/M/Y) = ");
  30. Serial.print(tm.Day);
  31. Serial.write('/');
  32. Serial.print(tm.Month);
  33. Serial.write('/');
  34. Serial.print(tmYearToCalendar(tm.Year));
  35. Serial.println();
  36. } else {
  37. if (RTC.chipPresent()) {
  38. Serial.println("The DS1307 is stopped. Please run the SetTime");
  39. Serial.println("example to initialize the time and begin running.");
  40. Serial.println();
  41. } else {
  42. Serial.println("DS1307 read error! Please check the circuitry.");
  43. Serial.println();
  44. }
  45. delay(9000);
  46. }
  47. delay(1000);
  48. }
  49.  
  50. void print2digits(int number) {
  51. if (number >= 0 && number < 10) {
  52. Serial.write('0');
  53. }
  54. Serial.print(number);
  55. }
Add Comment
Please, Sign In to add comment