Arduino LED Blink without Break

Dear All,

check the code below, while executing the for-loop, LED Blink function stops
i want to blink LED process to continue throughout, while my for-loop is executing

const int ledPin =  12;      // the number of the LED pin
int z=0;
int i=0;

int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated
long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);      
}

void loop()
{
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;   
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
    digitalWrite(ledPin, ledState);
  }
  z=0;
  for(i=0; z <1000; i++)
  {
  Serial.println(z);
  z++;
  }
  
}

i want to blink LED process to continue throughout, while my for-loop is executing

Your for loop is blocking.
Either use a timer interrupt for the blink, or open out the for loop and perform the action explicitly.

Thanks for reply
can you please help me out with timer examples

It would be simpler to open out the for loop.

 z=0;
  for(i=0; z <1000; i++)
  {
  Serial.println(z);
  z++;
  }

I think if you delete this then the blink will work again, what you have here is a delay, the for loop will not exit.
try
for (i=0; i<1000; i++)

Might be better loop.
It will still delay but at least it will exit.

Tom..... :slight_smile:

@AWOL

i use LED to set the status of my GPS (NO FIX - shortblink, 2D - Long Blink, 3D - ON).
So timer may help me
please provide me some sample codes or references

Thanks

@TOM

thanks for your reply,
i use LED to set the status of my GPS (NO FIX - shortblink, 2D - Long Blink, 3D - ON).

To make my query simple and understandable, in my code i shown a for-loop instead of my GPS Status function

@AWOL

Thanks for your idea of timer,
i did it with below code, now for-loop works and blink works continuously

#include "TimerOne.h"
 
void setup()
{
  Serial.begin(9600);
  pinMode(10, OUTPUT);
  Timer1.initialize(500000);         // initialize timer1, and set a 1/2 second period
  Timer1.pwm(10, 512);                // setup pwm on pin 9, 50% duty cycle
  Timer1.attachInterrupt(callback);  // attaches callback() as a timer overflow interrupt
}
 
void callback()
{
  digitalWrite(10, digitalRead(10) ^ 1);
}
 
void loop()
{
 for(int i=0; i <1000; i++)//while(z=10000);
  {
  Serial.println(i);
  }
}

The for loop will block for however long it takes to print a thousand integers.
Hopefully, a GPS status function will not block, and if it does, rewrite it so that it doesn't block.

Your query is pretty pointless.

Thank you
Will test with GPS and post the code here

 for(int i=0; i <1000; i++)//while(z=10000);

If you are going to have useless comments, they should be correct useless comments. Otherwise, they scream clueless.

You do what your useless comments to not give you away, don't you?