Skip to content

Instantly share code, notes, and snippets.

@toygame
Created March 4, 2018 11:41
Show Gist options
  • Save toygame/e7330e4134e844ef8bf2f66d1bab206f to your computer and use it in GitHub Desktop.
Save toygame/e7330e4134e844ef8bf2f66d1bab206f to your computer and use it in GitHub Desktop.
/*
Created by Thanapon@Arduino2Day.com
*/
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
bool state = 0;
BlynkTimer timer;
BLYNK_WRITE(V1)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
Serial.print("V1 Slider value is: ");
Serial.println(pinValue);
if (pinValue)
{
state = 1;
}
}
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
if (digitalRead(D2) == 1)
{
Blynk.virtualWrite(V1, 0);
}
}
void setup()
{
// Debug console
// Serial.begin(9600);
pinMode(D2, OUTPUT);
digitalWrite(D2, HIGH);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, myTimerEvent);
}
void loop()
{
Blynk.run();
timer.run();
if (state == 1)
{
Serial.println("1");
digitalWrite(D2, LOW);
delay(200);
digitalWrite(D2, HIGH);
Serial.println("0");
state = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment