Light a button instead of an LED

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

I have a similar request… I’d like to be able to select a widget (like timer or value display) and have it highlighted in some way. it would greatly simplify the design and keep UI clutter down. Thanks.

You can change the state of the button in the app from hardware.

Check: http://docs.blynk.cc/#blynk-main-operations-state-syncing

1 Like

Thanks Pavel…post moved to new thread.

@drewc228

Looks like your request is very different from initial topic. You should create a new one and try not to hijack the thread :wink: Then it’s more likely that your idea won’t get lost.

Thanks