Hello,how can store the sd card data in EEPROM based on event./
I made some code(with the help of forum) it will display the sd card data in lcd when i press the button.Here is the code
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
const int chipSelect = 10;
const int butPin = 7;
bool butState;
const int butlcd = 2;
bool butState1;
int analogPin=A0;
char Str1[15];
void setup()
{
lcd.begin(16,2);
lcd.backlight();
pinMode(butPin,INPUT_PULLUP);
pinMode(butlcd,INPUT_PULLUP);
pinMode(analogPin,INPUT);
Serial.begin(9600);
while (!Serial)
{
;
}
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect))
{
Serial.println("Card failed, or not present");
while (1);
}
Serial.println("Card initialized.");
}
void loop()
{
butState = digitalRead(butPin);
delay(1000);
if (butState==1)
{
//Default state. Do Nothing.
}
else
{
Serial.println("Data LOG");
String dataString = "";
int sensor = analogRead(analogPin);
dataString += String(sensor);
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile)
{
dataFile.println(dataString);
dataFile.close();
Serial.println(dataString);
}
else
{
Serial.println("error opening datalog.txt");
}}
butState1 = digitalRead(butlcd);
delay(500);
if (butState1==0)
{
readu();
}}
void readu()
{
File dataFile = SD.open("datalog.txt");
if (dataFile) {
Serial.println("datalog.txt");
// read from the file until there's nothing else in it:
while (dataFile.available()) {
char c = dataFile.read();
lcd.print(c);
Serial.print(c);
}
dataFile.close();
}
else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
delay(1000);
if (SD.exists("datalog.txt")) { // if "file.txt" exists, fill will be deleted
Serial.println("File exists.");
if (SD.remove("datalog.txt") == true) {
Serial.println("Successfully removed file.");
} else {
Serial.println("Could not removed file.");
}
}
}
Now i want to stored the data in EEPROM which was displayed in serial monitor as well as lcd.(last data stored in sd card).
In each button press data will update on same EEPROM ADDRESS.
Please advice me what are the modification in my program i have to be done for adopting these changes.
thank you.