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;
int r = analogRead(0);
if (digitalRead(SWITCH) == LOW) {
Serial.println("----Recording----");
}
while (addr <= 1024) {
digitalWrite(LED_BUILTIN, HIGH);
delay (250);
digitalWrite(LED_BUILTIN, LOW);
delay(750);
Serial.println(r);
EEPROM.put(addr, r);
addr = addr + 2;
delay(600);
}
while (true);
}
delay(600);
would make the duration of you loop a lot closer to 1 second. Indeed the other code would take a bit of time to, but my guess would be that it only takes 5ms per cycle. Depending on you application, that might be good enough. It might also be the case that you need it so precise that the precision of the crystal the Arduino uses isn't good enough.