I am trying to make my built in LED on my arduino blink every 1 second while recording my data and putting it in the EEPROM, but I am not sure how to do that. I am supposed to print data to the EEPROM every minute, until the EEPROM is full and while that is going on my built in LED should blink for approx 1 second. My problem seems to be that I am setting a delay to delay how long the data is stored on the EEPROM, but it is also affecting the time it takes for my LED to blink as it is waiting to blink as the data is stored. Any help would be appreciated, the code is below:
#include<EEPROM.h>
const int SWITCH = 4;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(SWITCH, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
int addr = 0;
float v;
float c;
int t = 0;
int r = analogRead(0);
if (digitalRead(SWITCH) == LOW) {
Serial.println("----Recording----");
while (addr <= 1024) {
Serial.println(r);
EEPROM.put(addr, r);
addr = addr + 2;
delay(600);
}
while (true);
}
else {
Serial.println("----Replaying----");
Serial.println("Time(s), Temp(C)");
while (addr <= 1024) {
t = t + 1;
EEPROM.get(addr, r);
addr = addr + 2;
v = r * 5.0 / 1024.0;
c = 100 * (v - 0.5);
Serial.print(t * 60);
Serial.print("\t");
Serial.println(c);
delay(1000);
}
while (true);
}
}