|
|
|
/************************************************************* |
|
|
|
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(); |
|
} |