Blink LED independtly

Hello,
I have written super-loop to read valve state from LoRa and show status with LED as shown below

#include <TimedBlink.h>

TimedBlink monitor(LED_BUILTIN);

void setup()
{
    Serial.begin(9600);
    pinMode(LED_BUILTIN, OUTPUT);
    monitor.blink(150, 50); // LED on for 150 ms and off for 50 ms.
}

void loop()
{
    // Read valve state from LoRa
    int valveState = GetValveState();

    if (valveState == 0)
    {
        // 0 means valve is closed, turn off LED
        digitalWrite(LED_BUILTIN, LOW);
    }
    else if (valveState == 1)
    {
        // 1 means valve is open, turn on LED
        digitalWrite(LED_BUILTIN, HIGH);
    }

    else if (valveState == -1)
    {
        //-1 means valve is opening, it takes some time, so blink LED
        monitor.blink(); // Call this as often as possible
    }
    //...
    //..
    // Other task
    //..
    //..
}

Issue I am facing is, " // Other task" takes some time, so LED is not blinking as expected,
anyway to make LED independently blink?

Take a view to the BlinkWithOut example to be found in the IDE.

You'll have to write other tasks such that they accomplish their goals by taking little tiny steps each time they are called, no single one of which will take very long.

The general concept is called a finite state machine, and it is the key to making things seems as if they are going on concurrently, kinda like juggling.

google is your friend

   arduino blink without delay


   arduino two things at once


   arduino finite state machine


   arduino finite state machine traffic lights

HTH

Consider yourself advanced when you realize you no longer need the help of strangers:

#include <TimedBlink.h>

You'll be able to role your own timed blink without no stinkin' library...

a7

it takes time to read data from LoRa and save it to Google Firebase, so in that period LED blink call is delayed, so LED keep on some time, and then off, but its not blinking.
I tried optimizing code all way, but time taken to read data from LoRa and Firebase to save not in control.
will Interrupt Routine help?
do we go for Free RTOS?

It possible that code could be broken into smaller chunks. But, we'll never know since you didn't post it.

its simple Firebase save data of sensor like humidity,temperature and soil moisture, even though we break code, it takes small time to save it and small time to read it from LoRa.
LED blinks, but not what user expect, 2-3sec on then 2-3sec of etc, i want it should blink perfectly.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.