Compliation error. Please help. I just want to blink 3 lights

#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#include <BlynkSimpleStream.h>

BlynkTimer timer;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "bML9YS";

const int Green=2;
const int Orange=3;
const int Red=4;

void setup() 
{
pinMode(2, OUTPUT); 
pinMode(3, OUTPUT); 
pinMode(4, OUTPUT); 

  Serial.begin(9600);
  Blynk.begin(Serial, auth);
}

void loop() 
{
  Blynk.run();
  timer.run();
  lightcycle();
  
}

void lightcycle()
{
  if BLYNK_WRITE(V1)
{
 if(param.asInt() == 1)
 {
digitalWrite(2, LOW);digitalWrite(3, LOW);digitalWrite(4, HIGH); delay(2000);
digitalWrite(2, LOW);digitalWrite(3, HIGH);digitalWrite(4, LOW); delay(2000);
digitalWrite(2, HIGH);digitalWrite(3, LOW);digitalWrite(4, LOW); delay(2000);
  }
else 
 {
digitalWrite(2, LOW);digitalWrite(3, LOW);digitalWrite(4, LOW); 
  }
 }
}

What is the error, and where does it occur?

Pete.

It says error compiling for board Arduino Mega 2560.

I think you’ll find that if you scroll up the compilation information then there will be more info available.

But, you can’t do this…

BLYNK_WITE(V1) is a function, and it can’t be inside another function (lightcycle in this case).

Pete.

Yes it throws this error. But How can I achieve this? I want to blink 3 leds one by one when I press V1 in the app

Read this…

Pete.

Thanks for providing this article. I have read it yesterday But in that case how would I add delay between those relays? Here I have the same case with LED’s

You need to read-up about using BlynkTimer in Timeout mode.

Pete.

I have read about BlinkTimer but unable to figure out how that will be useful here. I have posted the video. I want my LED’s to blink in this exact way . VID_20210326_064858.mp4 - Google Drive Please tell me how to make this possible with blynk

By using a BlynkTimer in Timeout mode instead of your delay commands.

Pete.

I recently came to know that Blynk has restrictions with delay. I want to blink 3 leds one after other like traffic signal lights with 1 sec frequency. Below is the code which is run on arduino normally. How can I do that without delay in Blynk. Please help me how to write that one line.

#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#include <BlynkSimpleStream.h>

BlynkTimer timer;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "bML9YS";

const int Green=2;
const int Orange=3;
const int Red=4;

void setup() 
{
pinMode(2, OUTPUT); 
pinMode(3, OUTPUT); 
pinMode(4, OUTPUT); 

  Serial.begin(9600);
  Blynk.begin(Serial, auth);
}

void loop() 
{
  Blynk.run();
  timer.run();
  BLYNK_WRITE(V1)
}
BLYNK_WRITE(V1)
{
 if(param.asInt() == 1)
 {
digitalWrite(2, LOW);digitalWrite(3, LOW);digitalWrite(4, HIGH); delay(2000);
digitalWrite(2, LOW);digitalWrite(3, HIGH);digitalWrite(4, LOW); delay(2000);
digitalWrite(2, HIGH);digitalWrite(3, LOW);digitalWrite(4, LOW); delay(2000);
  }
else 
 {
digitalWrite(2, LOW);digitalWrite(3, LOW);digitalWrite(4, LOW); 
  }
 }

We gave you some instructions on your other topic. Please dnt keep creating new topics. @PeteKnight ??

Topics merged, thanks for flagging this Dave.

@rameshpersuader as @daveblynk said, please don’t keep creating new topics about the same issue.
I’d suggest that you read the documentation for SimpleTimer - which BlynkTimer is based on - and read the topics on this forum regarding BlynkTimer in Timeout mode.
You probably won’t want to use the Timeout timer in a Lambda function in t5his case, as for what you want, you’d need nested Lamda functions, high becomes a bit complex.

Start_Timer_A()
{
  turn LED 1 ON  
  initialise timeout timer A, to call Timer_A_Ends() when it completes
}

Timer_A_Ends()
{
  turn LED 1 OFF
  call Start_Timer_B
}


Start_TimerB()
{
  turn LED 2 ON  
  initialise timeout timer B, to call Timer_B_Ends() when it completes
}

Timer_B_Ends()
{
  turn LED 2 OFF
  call Start_Timer_C
}


Start_Timer_C()
{
  turn LED 3 ON  
  initialise timeout timer C, to call Timer_C_Ends() when it completes
}

Timer_C_Ends()
{
  turn LED 3 OFF
  call Start_Timer_A (assuming you want this process to cycle repeatedly
}

Pete.

Hello Pete,
Can you please tell what am I doing wrong? The code is not working and also throwing error while compilation. Please help. I know this is too dumb as I’m unable to blink 3 LED’s.

// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#include <BlynkSimpleStream.h>
#include <SimpleTimer.h>

SimpleTimer timer;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "bMLxyWbo3wv-gMZ9YS";

const int Green=2;
const int Orange=3;
const int Red=4;

void setup() 
{
pinMode(2, OUTPUT); 
pinMode(3, OUTPUT); 
pinMode(4, OUTPUT); 

  Serial.begin(9600);
  Blynk.begin(Serial, auth);
  timer.enable(timerId);
}



void loop() 
{


  Blynk.run();
  timer.run();
  

  
  timerId = timer.setTimeout(1000, Green_On);
  timerId = timer.setTimeout(1000, Orange_On);
  timerId = timer.setTimeout(1000, Red_On);
 
}

void Red_On()  
{
digitalWrite(Green, LOW);digitalWrite(Orange, LOW);digitalWrite(Red, HIGH); 
}

void Orange_On()  
{
digitalWrite(Green, LOW);digitalWrite(Orange, HIGH);digitalWrite(Red, LOW); 
}

void Green_On()  
{
digitalWrite(Green, HIGH);digitalWrite(Orange, LOW);digitalWrite(Red, LOW); 
}

I think you need to re-read what I wrote, and take that stuff out of your vid loop.

Pete.