Created
December 28, 2022 10:05
-
-
Save lARSHADl/4ab98969fab3b23594af19f47b9f30ee to your computer and use it in GitHub Desktop.
traffic leds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************************* | |
This is a simple demo of sending and receiving some data. | |
Be sure to check out other examples! | |
*************************************************************/ | |
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud | |
// See the Device Info tab, or Template settings | |
#define BLYNK_TEMPLATE_ID "TMPLzKn_S2WG" | |
#define BLYNK_DEVICE_NAME "Quickstart Device" | |
#define BLYNK_AUTH_TOKEN "" | |
// Comment this out to disable prints and save space | |
#define BLYNK_PRINT Serial | |
int red = D1; // 5; / | |
int yellow = D2; //4; | |
int greenf = D6; //12; | |
int greenr = D7; //14; | |
int bypass = 0 ; | |
#include <ESP8266WiFi.h> | |
#include <BlynkSimpleEsp8266.h> | |
char auth[] = BLYNK_AUTH_TOKEN; | |
// Your WiFi credentials. | |
// Set password to "" for open networks. | |
char ssid[] = ""; | |
char pass[] = ""; | |
BlynkTimer timer; | |
// This function is called every time the Virtual Pin 0 state changes | |
BLYNK_WRITE(V4) // Executes when the value of virtual pin 0 changes | |
{ | |
if(param.asInt() == 1) | |
{ | |
bypass = 1; | |
digitalWrite(red,0); | |
digitalWrite(yellow,0); | |
digitalWrite(greenf,1); | |
digitalWrite(greenr,1); | |
} | |
else{ | |
digitalWrite(greenf,0); | |
digitalWrite(greenr,0); | |
red_on(); | |
} | |
} | |
void red_on() | |
{ if (bypass == 0) { | |
digitalWrite(greenf,0); | |
digitalWrite(greenr,0); | |
digitalWrite(yellow,0); | |
digitalWrite(red,1); | |
Serial.println("Red"); | |
timer.setTimeout(30000L, yellow_on); | |
} | |
} | |
void yellow_on() | |
{ Serial.println("yellow"); | |
digitalWrite(red,0); | |
digitalWrite(yellow,1); | |
timer.setTimeout(2000L, green_on); | |
} | |
void green_on(){ | |
Serial.println("All green"); | |
digitalWrite(red,0); | |
digitalWrite(yellow,0); | |
digitalWrite(greenf,1); | |
digitalWrite(greenr,1); | |
timer.setTimeout(30000L, red_on); | |
} | |
void setup() | |
{ | |
pinMode(red, OUTPUT); | |
pinMode(yellow, OUTPUT); | |
pinMode(greenf, OUTPUT); | |
pinMode(greenr, OUTPUT); | |
// Debug console | |
Serial.begin(115200); | |
Blynk.begin(auth, ssid, pass); | |
red_on(); | |
// You can also specify server: | |
//Blynk.begin(auth, ssid, pass, "blynk.cloud", 80); | |
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080); | |
// Setup a function to be called every second | |
} | |
void loop() | |
{ | |
Blynk.run(); | |
timer.run(); | |
// You can inject your own code or combine it with other sketches. | |
// Check other examples on how to communicate with Blynk. Remember | |
// to avoid delay() function! | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
inital comment