Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setTime() {
- // January 21, 2014 at 3am you would call:
- // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
- DateTime now = rtc.now();
- int newYear;
- int newMonth;
- int newDay;
- int newHour;
- int newMinute;
- int newSecond;
- Serial.println(" > Enter time (!TddMMyyyyhhmmss)");
- while (! (Serial.available() > 0));
- String time_string = Serial.readString();
- newDay = time_string.substring(2, 4).toInt();
- newMonth = time_string.substring(4, 6).toInt();
- newYear = time_string.substring(6, 10).toInt();
- newHour = time_string.substring(10, 12).toInt();
- newMinute = time_string.substring(12, 14).toInt();
- newSecond = time_string.substring(14, 16).toInt();
- Serial.print(" > New time - ");
- Serial.print(newYear, DEC);
- Serial.print('/');
- Serial.print(newMonth, DEC);
- Serial.print('/');
- Serial.print(newDay, DEC);
- Serial.print(' ');
- Serial.print(newHour, DEC);
- Serial.print(':');
- Serial.print(newMinute, DEC);
- Serial.print(':');
- Serial.print(newSecond, DEC);
- Serial.println();
- Serial.println(" > Change time? (Y/N)");
- while (! (Serial.available() > 0));
- if (Serial.readString() == "Y") {
- rtc.adjust(DateTime(newYear, newMonth, newDay, newHour, newMinute, newSecond));
- Serial.print(" > Time set to ");
- DateTime now = rtc.now();
- Serial.print(now.year(), DEC);
- Serial.print('/');
- Serial.print(now.month(), DEC);
- Serial.print('/');
- Serial.print(now.day(), DEC);
- Serial.print(' ');
- Serial.print(now.hour(), DEC);
- Serial.print(':');
- Serial.print(now.minute(), DEC);
- Serial.print(':');
- Serial.print(now.second(), DEC);
- Serial.println();
- Serial.println(" Sucsesfull!");
- } else {
- Serial.println(" > Canceled");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement