-
Notifications
You must be signed in to change notification settings - Fork 0
/
eeprom.ino
27 lines (24 loc) · 782 Bytes
/
eeprom.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
void init_EEPROM(void) {
EEPROM.begin();
// if value for seconds, that is read from EEPROM, is invalid
if (EEPROM.read(SecEepromAddress) < 0 || EEPROM.read(SecEepromAddress) >= 60) {
Serial.println("Read EEPROM values invalid, setting new values");
// set default time values
secs = 0;
mins = 0;
hrs = 0;
// write them to EEPROM
write_time_to_EEPROM();
} else {
// else read time values from EEPROM
Serial.println("EEPROM values valid, copying them");
secs = EEPROM.read(SecEepromAddress);
mins = EEPROM.read(MinEepromAddress);
hrs = EEPROM.read(HrEepromAddress);
}
}
void write_time_to_EEPROM(void) {
EEPROM.write(SecEepromAddress, secs);
EEPROM.write(MinEepromAddress, mins);
EEPROM.write(HrEepromAddress, hrs);
}