Hello everyone, I’m using mega 2560 and this code is not working. But I don’t have any error in compilation. Can someone tell me If I have done anything wrong? Is there something worng with Blynk initialisation? I have tried everything. I’m using serial connection. There are 4 buttons V1 to V4 and conditions are mentioned in those functions if none of those conditions satisy the function named normal should run in loop. FYI it’s a traffic signal project. The code executes everything until Blynk.begin(Serial, auth); is mentioned in setup and after that it doesn’t do anything. Please help.
#include <Arduino.h>
#include <LiquidCrystal.h>
#include <BlynkSimpleStream.h>
#include <FastLED.h>
#include <SoftwareSerial.h>
#define LED_TYPE WS2811
#define NUM_LEDS_PER_STRIP 3
#define COLOR_ORDER BGR
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
SoftwareSerial DebugSerial(2, 3); // RX, TX
CRGB L1[NUM_LEDS_PER_STRIP]; //L1A Stud Alert ///Lane stud alerts don't forget to update before code pivot...
CRGB L2[NUM_LEDS_PER_STRIP]; //L2A Stud Alert
CRGB L3[NUM_LEDS_PER_STRIP]; //L3A Stud Alert
CRGB L4[NUM_LEDS_PER_STRIP]; //L4A Stud Alert
char auth[] = "bMLxyWboMZ9YS";
int buttonstate1=0;
unsigned long delayStart = 0; // the time the delay started
unsigned long light_delay = 1000; // the time the delay runs
unsigned long half_delay = 500;
unsigned long studs =200;
unsigned long screen_delay =2500;
const int L1G=2; ////////////////L1-GREEN
const int L1O=3; ////////////////L1-ORANGE
const int L1R=4; ////////////////L1-RED
const int L2G=5; ////////////////L2-GREEN
const int L2O=6; ////////////////L2-ORANGE
const int L2R=7; ////////////////L2-RED
const int L3G=14; ////////////////L3-GREEN
const int L3O=15; ////////////////L3-ORANGE
const int L3R=16; ////////////////L3-RED
const int L4G=17; ////////////////L4-GREEN
const int L4O=18; ////////////////L4-ORANGE
const int L4R=19; ////////////////L4-RED
const int L1A=22; ////////////////L1-Stud Alert
const int L2A=24; ////////////////L2-Stud Alert
const int L3A=26; ////////////////L3-Stud Alert
const int L4A=28; ////////////////L4-Stud Alert
void setup()
{
FastLED.addLeds<WS2811, 23, BRG>(L1, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2811, 24, BRG>(L2, NUM_LEDS_PER_STRIP);//CRGB::Black; Raipur test
FastLED.addLeds<WS2811, 26, BRG>(L3, NUM_LEDS_PER_STRIP);//CRGB::Black;
FastLED.addLeds<WS2811, 28, BRG>(L4, NUM_LEDS_PER_STRIP);//CRGB::Black;
FastLED.clear();
FastLED.show();
lcd.begin(16, 2);
Serial.begin(9600);
pinMode(L1G, OUTPUT);
pinMode(L1O, OUTPUT);
pinMode(L1R, OUTPUT);
pinMode(L2G, OUTPUT);
pinMode(L2O, OUTPUT);
pinMode(L2R, OUTPUT);
pinMode(L3G, OUTPUT);
pinMode(L3O, OUTPUT);
pinMode(L3R, OUTPUT);
pinMode(L4G, OUTPUT);
pinMode(L4O, OUTPUT);
pinMode(L4R, OUTPUT);
pinMode(L1A, OUTPUT);
pinMode(L2A, OUTPUT);
pinMode(L3A, OUTPUT);
pinMode(L4A, OUTPUT);
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= screen_delay) {
Serial.println("Ready");
}
lcd.clear();
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= screen_delay) {
Serial.println("Check");
}
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= half_delay) {
Serial.println("Lane 1 blink");
digitalWrite(L1G, HIGH);digitalWrite(L1O, HIGH);digitalWrite(L1R, HIGH);
}
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= half_delay) {
digitalWrite(L1G, LOW);digitalWrite(L1O, LOW);digitalWrite(L1R, LOW);
digitalWrite(L2G, HIGH);digitalWrite(L2O, HIGH);digitalWrite(L2R, HIGH);
}
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= half_delay) {
digitalWrite(L1G, LOW);digitalWrite(L1O, LOW);digitalWrite(L1R, LOW);
digitalWrite(L2G, HIGH);digitalWrite(L2O, HIGH);digitalWrite(L2R, HIGH);
}
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= half_delay) {
digitalWrite(L2G, LOW);digitalWrite(L2O, LOW);digitalWrite(L2R, LOW);
digitalWrite(L3G, HIGH);digitalWrite(L3O, HIGH);digitalWrite(L3R, HIGH);
}
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= half_delay) {
digitalWrite(L3G, LOW);digitalWrite(L3O, LOW);digitalWrite(L3R, LOW);
digitalWrite(L4G, HIGH);digitalWrite(L4O, HIGH);digitalWrite(L4R, HIGH);
}
digitalWrite(L4G, LOW);digitalWrite(L4O, LOW);digitalWrite(L4R, LOW);
Serial.println("Shuru");
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= screen_delay)
{
Serial.println("Test");
}
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= light_delay)
{
digitalWrite(L1G, HIGH);digitalWrite(L1O, HIGH);digitalWrite(L1R, HIGH);//delay(10);
digitalWrite(L2G, HIGH);digitalWrite(L2O, HIGH);digitalWrite(L2R, HIGH);//delay(10);
digitalWrite(L3G, HIGH);digitalWrite(L3O, HIGH);digitalWrite(L3R, HIGH);//delay(10);
digitalWrite(L4G, HIGH);digitalWrite(L4O, HIGH);digitalWrite(L4R, HIGH);
}
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= light_delay)
{
// turn them off before start the loop
digitalWrite(L1G, LOW);digitalWrite(L1O, LOW);digitalWrite(L1R, LOW);//delay(10);
digitalWrite(L2G, LOW);digitalWrite(L2O, LOW);digitalWrite(L2R, LOW);//delay(10);
digitalWrite(L3G, LOW);digitalWrite(L3O, LOW);digitalWrite(L3R, LOW);//delay(10);
digitalWrite(L4G, LOW);digitalWrite(L4O, LOW);digitalWrite(L4R, LOW);
}
lcd.clear();
lcd.setCursor(0,0);lcd.print(" NORMAL LANE ");
lcd.setCursor(0,1);
lcd.print(" MOVEMENT ACTIVE ");
Blynk.begin(Serial, auth);
}
BLYNK_WRITE(V1)
{
buttonstate1 = param.asInt();
if(buttonstate1 == 1)
{
lcd.setCursor(0,0);lcd.print("FIRST LANE PASS");
digitalWrite(L1R, LOW);digitalWrite(L1G, HIGH);digitalWrite(L2R, HIGH);digitalWrite(L3R, HIGH);digitalWrite(L4R, HIGH); Serial.print(" First Lane Active"); //digitalWrite(L1A, HIGH);
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= 200)
{
L1[0] = CRGB::Red; FastLED.setBrightness(64 );
FastLED.show();
}
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= 200)
{
L1[0] = CRGB::Blue;
FastLED.show();
}
/* L2[0] = CRGB::Yellow;
FastLED.show();
delay(200);*/
digitalWrite(L1G, LOW); //digitalWrite(L1A, LOW);
L1[0] = CRGB::Black;
FastLED.show();
}
}
BLYNK_WRITE(V2)
{
buttonstate1 = param.asInt();
if(buttonstate1 == 1)
{
lcd.setCursor(0,0);lcd.print("SECOND LANE PASS");
digitalWrite(L2R, LOW);digitalWrite(L2G, HIGH);digitalWrite(L1R, HIGH);digitalWrite(L3R, HIGH);digitalWrite(L4R, HIGH); Serial.print(" Second Lane Active"); //digitalWrite(L2A, HIGH);
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= 200)
{
L2[0] = CRGB::Red; FastLED.setBrightness(64 );
FastLED.show();
}
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= 200)
{
L2[0] = CRGB::Blue;
FastLED.show();
}
/* L2[0] = CRGB::Yellow;
FastLED.show();
delay(200);*/
digitalWrite(L2G, LOW);//digitalWrite(L2A, LOW);
L2[0] = CRGB::Black;
FastLED.show();
}
}
BLYNK_WRITE(V3)
{
buttonstate1 = param.asInt();
if(buttonstate1 == 1)
{
lcd.setCursor(0,0);lcd.print("THIRD LANE PASS");
digitalWrite(L3R, LOW);digitalWrite(L3G, HIGH);digitalWrite(L2R, HIGH);digitalWrite(L1R, HIGH);digitalWrite(L4R, HIGH); Serial.print(" Third Lane Active");//digitalWrite(L3A, HIGH);
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= 200)
{
L3[0] = CRGB::Red; FastLED.setBrightness(64 );
FastLED.show();
}
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= 200)
{
L3[0] = CRGB::Blue;
FastLED.show();
}
/* L3[0] = CRGB::Yellow;
FastLED.show();
delay(200);*/
digitalWrite(L3G, LOW);//digitalWrite(L3A, LOW);
L3[0] = CRGB::Black;
FastLED.show();
}
}
BLYNK_WRITE(V4)
{
buttonstate1 = param.asInt();
if(buttonstate1 == 1)
{
lcd.setCursor(0,0);lcd.print("FOURTH LANE PASS");
digitalWrite(L4R, LOW);digitalWrite(L4G, HIGH);digitalWrite(L2R, HIGH);digitalWrite(L3R, HIGH);digitalWrite(L1R, HIGH); Serial.print(" Fourth Lane Active");//digitalWrite(L4A, HIGH);
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= 200)
{
L4[0] = CRGB::Red; FastLED.setBrightness(255 );
FastLED.show();
}
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= 200)
{
L4[0] = CRGB::Blue;
FastLED.show();
}
/* L4[0] = CRGB::Yellow;
FastLED.show();
delay(200);*/
digitalWrite(L4G, LOW);//digitalWrite(L4A, LOW);
L4[0] = CRGB::Black;
FastLED.show();
}
}
void normal()
{
//1st lane
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= light_delay)
{
digitalWrite(L1R, LOW);digitalWrite(L1G, HIGH);digitalWrite(L2R, HIGH);digitalWrite(L3R, HIGH);digitalWrite(L4R, HIGH);
}
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= half_delay)
{
digitalWrite(L1G, LOW);digitalWrite(L1O, HIGH);
}
digitalWrite(L1O, LOW);digitalWrite(L1R, HIGH);
//2nd lane
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= light_delay)
{
digitalWrite(L2R, LOW);digitalWrite(L2G, HIGH);digitalWrite(L1R, HIGH);digitalWrite(L3R, HIGH);digitalWrite(L4R, HIGH);
}
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= half_delay)
{
digitalWrite(L2G, LOW);digitalWrite(L2O, HIGH);
}
digitalWrite(L2O, LOW);digitalWrite(L2R, HIGH);
//3nd lane
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= light_delay)
{
digitalWrite(L3R, LOW);digitalWrite(L3G, HIGH);digitalWrite(L2R, HIGH);digitalWrite(L1R, HIGH);digitalWrite(L4R, HIGH);
}
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= half_delay)
{
digitalWrite(L3G, LOW);digitalWrite(L3O, HIGH);
}
digitalWrite(L3O, LOW);digitalWrite(L3R, HIGH);
//4th lane
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= light_delay)
{
digitalWrite(L4R, LOW);digitalWrite(L4G, HIGH);digitalWrite(L2R, HIGH);digitalWrite(L3R, HIGH);digitalWrite(L1R, HIGH);
}
delayStart = millis(); // ok we are stating
while ((millis() - delayStart) <= half_delay)
{
digitalWrite(L4G, LOW);digitalWrite(L4O, HIGH);
}
digitalWrite(L4O, LOW);digitalWrite(L4R, HIGH);
}
void loop()
{
normal();
Blynk.run();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}