Sparkcorepulltimer instead of delay function

hello
am trying to avoid the delay function and use the sparkcorepulledtimer in the photon .
so i have some q just to understabd plz.
is it delay() function not good to use in the void loop ?or can i use it in the void setup or out of void loop?

and have this code its example for the simpletimer for the photon so if i wanna do this blink two leds
digitalwrite(led,HIGH);
delay(1000);
digitalWrite(led,LOW);
delay(1000);
digitalwrite(led2,HIGH);
delay(1000);
digitalwrite(led2,LOW);
delay(1000);
how i can transfer this to this code

#include "SparkCorePolledTimer/SparkCorePolledTimer.h"
#define led D0
#define led2 D1


SparkCorePolledTimer updateTimer(1000);  //Create a timer object and set it's timeout in milliseconds
void OnTimer(void);   //Prototype for timer callback method

void setup() {
  Serial1.begin(115200);  
  updateTimer.SetCallback(OnTimer);
  pinMode(led,OUTPUT);
  pinMode(led2,OUTPUT);
  
}

void loop() {
   updateTimer.Update();
}

void OnTimer(void) {  //Handler for the timer, will be called automatically
 
}

i would appreciate just to explian to me how ,i already did research and i couldnt get it from the projects that using it .
thanks

Try not to use delay() anywhere.

Think you are missing the Blynk library and also Blynk.run() from loop().

If we just think about the first LED to start with.

bool LEDstate = false;  // start with LED off

void OnTimer(void) {  //Handler for the timer, will be called automatically
  if (LEDstate == true) {  // LED is ON
    digitalWrite(led, 0);  // so turn it OFF
    LEDstate = false;      
  } else {                 // LED if OFF
    digitalWrite(led, 1);  // so turn it ON
    LEDstate = true;
  } 
}

Then you need to move on to Blynk controlling the LED rather than just the 1 second timer loop.

thank u very much sir
i appreciate ur help
yes the blynk i havnt added it yet just wanted to understand how that works .thank u again

so for the second led that i wanna add
i have to do another if and else
or just add another else {}?
how it would be
sorry to bother u

so first one turn on then off then the second one on then off then comes to the first one again like loop

i tried to do it this way
but i was struggling how to add the second led

// This #include statement was automatically added by the Particle IDE.
#include "blynk/blynk.h"
#define ON 255
#define OFF 0



char auth[] = "xxx";



const int ledPin =  13;
int ledState = 0;
int ledStates=0;
unsigned long previousMillis = 0;
unsigned long interval = 1000;
 
void setup() {
     Serial.begin(9600); // See the connection status in Serial Monitor
  Blynk.begin(auth);  // Here your Arduino connects to the Blynk Cloud.
  
  pinMode(ledPin, OUTPUT);
} 
 
void loop() {
    
    Blynk.run();
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;
    if (ledState == 0)
      ledState = 255;
      //Blynk.virtualWrite(V4,ON);
    else
      ledState = 0;
    digitalWrite(ledPin, ledState);
    Blynk.virtualWrite(V4,ledState);
    
  
  }
  
}

In the real world nobody actually has 2 LED’s flashing one after the other so I’m not going to waste your time and mine showing you how to do it.

Suggest you get the device connected to Blynk, forget millis(), take the rubbish out of loop() and then we look at controlling the LED’s (as many as you like).

u right sir
thank u for ur help :slight_smile: