Skip to content

Instantly share code, notes, and snippets.

@yarogniew
Last active August 16, 2019 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yarogniew/efbb00f71d3ce8ca8907ba616c213927 to your computer and use it in GitHub Desktop.
Save yarogniew/efbb00f71d3ce8ca8907ba616c213927 to your computer and use it in GitHub Desktop.
/*************************************************************
Blynk using a LED widget on your phone!
App project setup:
LED widget on V3
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266_SSL.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";
// Select your pin with physical button
const int btnPin = 1; // TX na D1 mini
WidgetLED led3(V3);
BlynkTimer timer;
// V3 LED Widget represents the physical button state
boolean btnState = false;
void buttonLedWidget()
{
// Read button
boolean isPressed = (digitalRead(btnPin) == LOW);
// If state has changed...
if (isPressed != btnState) {
if (isPressed) {
led3.on();
} else {
led3.off();
}
btnState = isPressed;
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
// Setup physical button pin (active low)
pinMode(btnPin, INPUT_PULLUP);
timer.setInterval(500L, buttonLedWidget);
}
void loop()
{
Blynk.run();
timer.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment