user51474: 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);
}


user37523: As Rudy mentions in his answer, don't use delay(), and start with the BlinkWithoutDelay example that comes with the Arduino IDE. Here is a sketch to get you started. If you compare it to the BlinkWithoutDelay example, it's very similar, except I added some button code to "start" and "stop" the LED flashing.
const byte SWITCH = 4;
const byte ledPin = 13;
const unsigned long oneSecond = 1000;
unsigned long previousMillis = 0;
byte ledState = LOW;
byte recording = 0;

void setup(){
  pinMode(ledPin, OUTPUT);
  pinMode(SWITCH, INPUT_PULLUP);
}

void loop(){

  unsigned long currentMillis = millis();

  if(digitalRead(SWITCH) == LOW){
    recording = 1;
  }
  else{
    recording = 0;
    digitalWrite(ledPin, LOW);
  }

  if(currentMillis - previousMillis >= oneSecond){

    previousMillis = currentMillis;

    if(recording){
      if(ledState == LOW){
        ledState = HIGH;
      }
      else{
        ledState = LOW;
      }
    }
    digitalWrite(ledPin, ledState);
  }
}


user47766: Do not use delay(). Use the example Blink without delay example as the starting point.
https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
Find it under Examples    02.Digital
Simple code like delay() is called blocking code. It prevents other things from happening until t is through. That is acceptable in very sequential linear programs where only one thing is ever happening. And you have discovered the limitation of that. Time to get more sophisticated in your programming.
Please open the example and play with it. Make sure you understand it before thinking of how to modify your code. 

51474: <p>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:</p>

<pre><code>#include&lt;EEPROM.h&gt;
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 &lt;= 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);
}
</code></pre>
 37523: <p>As Rudy mentions in his answer, don't use <code>delay()</code>, and start with the <code>BlinkWithoutDelay</code> example that comes with the Arduino IDE. Here is a sketch to get you started. If you compare it to the <code>BlinkWithoutDelay</code> example, it's very similar, except I added some button code to "start" and "stop" the LED flashing.</p>

<pre><code>const byte SWITCH = 4;
const byte ledPin = 13;
const unsigned long oneSecond = 1000;
unsigned long previousMillis = 0;
byte ledState = LOW;
byte recording = 0;

void setup(){
  pinMode(ledPin, OUTPUT);
  pinMode(SWITCH, INPUT_PULLUP);
}

void loop(){

  unsigned long currentMillis = millis();

  if(digitalRead(SWITCH) == LOW){
    recording = 1;
  }
  else{
    recording = 0;
    digitalWrite(ledPin, LOW);
  }

  if(currentMillis - previousMillis &gt;= oneSecond){

    previousMillis = currentMillis;

    if(recording){
      if(ledState == LOW){
        ledState = HIGH;
      }
      else{
        ledState = LOW;
      }
    }
    digitalWrite(ledPin, ledState);
  }
}
</code></pre>
 47766: <p>Do not use delay(). Use the example Blink without delay example as the starting point.</p>

<p><a href="https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay" rel="nofollow noreferrer">https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay</a></p>

<p>Find it under Examples    02.Digital</p>

<p>Simple code like delay() is called blocking code. It prevents other things from happening until t is through. That is acceptable in very sequential linear programs where only one thing is ever happening. And you have discovered the limitation of that. Time to get more sophisticated in your programming.</p>

<p>Please open the example and play with it. Make sure you understand it before thinking of how to modify your code. </p>
