How to use simple timer function?

how to use simple timer function? when i used delay function the following program working properly but when i used simpletimer fuction the LED notification on dashboard is turns ON for few seconds and then it turns off. I want LED notification when LED connected to pin13 is turn ON.
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>
#include <SimpleTimer.h>
// Set ESP8266 Serial object
#define EspSerial Serial

    ESP8266 wifi(EspSerial);
    char auth[] = "auth token";
    int prev = -1;
    int B1V;
    int BUTTON1 = 13;
    SimpleTimer timer;
    void setup()
    {
      // Set console baud rate
      Serial.begin(9600);
    // Set ESP8266 baud rate
      EspSerial.begin(9600);
      Blynk.begin(auth, wifi, "saurabh", "saurabh0639");
      timer.setInterval(1000L, sendUptime);
    }
    void sendUptime()
    {
    B1V = digitalRead(BUTTON1);
    if (B1V != prev) {
    if (B1V) {
    Blynk.virtualWrite(V1, 255);
    } else {
    Blynk.virtualWrite(V1, 0);
    } 
    }
    }
    void loop()
    {
      Blynk.run();
      timer.run(); // SimpleTimer is working
    }

Have you checked if the hardware is responsible for this? Seeing as pin 13 is the built-in LED, you can actually check very quick to see if the LED is indeed on or off.\

-edit-

I think you are overthinking this:

void sendUptime()
{
  int button1 = digitalRead(13);

  if(button1 == 0)
  {
    Blynk.virtualWrite(V1, LOW);
  }
  else
  {
    Blynk.virtualWrite(V1, HIGH);
  }
}
1 Like