Hi
I am designing a bell timer that rings the bell at predetermined times input by a user. I have got everything working but am really struggling with reading and writing strings to and from the EEprom (Mega 2560 IDE 1.8.5)
The input for these preset times comes in as a 5 character string stored in an array. So for example the string 31430 would ring the bell on Wednesday (day 3, first character) at half past 2 in the afternoon (last 4 characters). I can enter these 'bell ring times' through the LCD menu system using push buttons.
I have written a 5 character conversion routine to determinate the correct time from a RTC and this scan the array so when its 5 character output matches one of the 'bell ring times' it sounds the bell.
I have already done the coding and got all the functionality and menus working and the bell rings at the correct times.
What I need to do is store the contents of the array to the EEprom so in case of power failure that 'bell ring times' can be read back from the EEprom into the string array as the five original characters. This is important because there might be up to a hundred different times in a week that the bell could ring.
I have posted a simplified bit of code below with some explanations contained within it. If anybody could point me in the right direction I would be grateful.
Thanks in advance
Chazza
#include <EEPROM.h>
String rt[10];
// will have upto a hundred entries in this String array
// only first 10 shown in this example.
// String will always be 5 characters long.
// String will always contains numeric characters
// lowest string could be "00000" (five zero's)
// highest string could be "72359"
// Have to be able to read the string back without trucation so for example, rt[4] which is
// shown in this example as "00001" would need to read back from the EEprom as "00001" once it has been converted back to a string if the solution is to store it in another format.
void setup() {
Serial.begin(9600);
// will have upto a hundred entries in this String array. Only 10 shown in this example
// String will always be 5 characters long.
// string can be changed by user input so array values and positions are not fixed.
// String will always contains numeric characters
// lowest string could be "00000" (five zero's)
// highest string could be "99999" (five nines)
rt[0] = "10730";
rt[1] = "30730";
rt[2] = "40610";
rt[3] = "20730";
rt[4] = "00001";
rt[5] = "10736";
rt[6] = "99999";
rt[7] = "51620";
rt[8] = "20755";
rt[9] = "72359";
rt[10] = "41230";
}
void loop() {
writeEEprom () ;
readEEprom () ;
int wait = 1;
while (wait == 1) {
// do nothing but wait here
}
}
void writeEEprom () {
// write values to EEprom
for (int i = 0 ; i <= 10; i++) {
Serial.print("Writing array value :");
Serial.print(rt*);*
- Serial.print(" to EEprom Address :");*
- Serial.println(i);*
_ EEPROM.put(i, rt*.toInt());_
_ }_
_}_
void readEEprom () {
_ // read values from EEprom*_
* for (int i = 0 ; i <= 10; i++) {*
* Serial.print("EEprom address ");*
* Serial.println(i);*
* Serial.print (" = ");*
* Serial.println(EEPROM.read(i));*
* }*
}
_______________________________________________________________