Hi everyone
my current project uses a button in push mode to toggle the state of a pin(turn my lights on and off), i then have an LED in the app recieving data and displaying the state of the lights.
is it possible to have the button light up instead of needing a separate LED… could i Blynk.virtualWrite to the same virtual pin that is assigned to the button?
here is my code so far:
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <EEPROM.h>
int addr = 0;
int state = 0;
char auth[] = "xxx";
WidgetLED led1(12);
void setup()
{
EEPROM.begin(512);
pinMode(14, OUTPUT);
Blynk.begin(auth, "xxx", "xxx");
int value = EEPROM.read(addr);
if (value == 1) {
digitalWrite(14, 0);
EEPROM.write(addr, 0);
EEPROM.commit();
}
if (value == 0) {
digitalWrite(14, 1);
EEPROM.write(addr, 1);
EEPROM.commit();
}
while (Blynk.connect() == false) {
// Wait until connected
}
state = digitalRead(14);
if (state == 1) {
led1.on();
}
else {
led1.off();
}
}
BLYNK_WRITE(V2)
{
if (param.asInt() == 1)
{
digitalWrite(14, !digitalRead(14));
delay(200);
state = digitalRead(14);
if (state == 1) {
led1.on();
}
else {
led1.off();
};
EEPROM.write(addr, state);
EEPROM.commit();
}
}
void loop()
{
Blynk.run();
}