Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. void setTime() {
  2. // January 21, 2014 at 3am you would call:
  3. // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  4.  
  5. DateTime now = rtc.now();
  6. int newYear;
  7. int newMonth;
  8. int newDay;
  9. int newHour;
  10. int newMinute;
  11. int newSecond;
  12.  
  13.  
  14. Serial.println(" > Enter time (!TddMMyyyyhhmmss)");
  15.  
  16. while (! (Serial.available() > 0));
  17. String time_string = Serial.readString();
  18. newDay = time_string.substring(2, 4).toInt();
  19. newMonth = time_string.substring(4, 6).toInt();
  20. newYear = time_string.substring(6, 10).toInt();
  21. newHour = time_string.substring(10, 12).toInt();
  22. newMinute = time_string.substring(12, 14).toInt();
  23. newSecond = time_string.substring(14, 16).toInt();
  24.  
  25. Serial.print(" > New time - ");
  26.  
  27. Serial.print(newYear, DEC);
  28. Serial.print('/');
  29. Serial.print(newMonth, DEC);
  30. Serial.print('/');
  31. Serial.print(newDay, DEC);
  32. Serial.print(' ');
  33. Serial.print(newHour, DEC);
  34. Serial.print(':');
  35. Serial.print(newMinute, DEC);
  36. Serial.print(':');
  37. Serial.print(newSecond, DEC);
  38. Serial.println();
  39.  
  40. Serial.println(" > Change time? (Y/N)");
  41. while (! (Serial.available() > 0));
  42.  
  43. if (Serial.readString() == "Y") {
  44. rtc.adjust(DateTime(newYear, newMonth, newDay, newHour, newMinute, newSecond));
  45. Serial.print(" > Time set to ");
  46.  
  47. DateTime now = rtc.now();
  48. Serial.print(now.year(), DEC);
  49. Serial.print('/');
  50. Serial.print(now.month(), DEC);
  51. Serial.print('/');
  52. Serial.print(now.day(), DEC);
  53. Serial.print(' ');
  54. Serial.print(now.hour(), DEC);
  55. Serial.print(':');
  56. Serial.print(now.minute(), DEC);
  57. Serial.print(':');
  58. Serial.print(now.second(), DEC);
  59. Serial.println();
  60.  
  61. Serial.println(" Sucsesfull!");
  62. } else {
  63. Serial.println(" > Canceled");
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement