Ok - a simple question on how to light a virtual LED

sorry for this eventually stupid beginner question:
I have a button (push) and two LEDs, all with a virtual Pin.

If I push the button it should light either one of the two LEDs.
However, I dont even get it to work with a simple code:

BLYNK_READ(6)
{
  // This command writes Arduino's uptime in seconds to Virtual Pin (5)
 Blynk.virtualWrite(7, 0); Blynk.virtualWrite(8, 1);
}

where 6 is the Switch and 7 and 8 are LEDs, all virtual.

So while pressing the button led 8 should light, right? nothin is happening

Whats the deal about that? Can anyone help?

@currymuetze

Have a look here

Briefly :

BLYNK_READ(6)

should be

BLYNK_WRITE(6)

Hi All,

I worked out how the Blynk LED works by trial an error. Initially I thought an output of LOW\HIGH or 0\1 would make the LED light up but I was mistaken.

It appears the the LED in the Blynk app has brightness control. It’s not just an on/off LED!

The value range is 0 to 1023.

If you configure an LED to be connected to Virtual Pin 2 the Arduino code is:

Blynk.virtualWrite(2, 0); //turn off
Blynk.virtualWrite(2, 1023); //turn on - 100% brightness
Blynk.virtualWrite(2, 511); //50% brightness

A complete Arduino script to alternatively flash two LED’s on the Blynk App looks like this:

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
int ledState = LOW;             // ledState used to set the LED
int VirtualPinA = 0;
int VirtualPinB = 1;
const long interval = 1000;           // interval at which to blink (milliseconds)
unsigned long previousMillis = 0;        // will store last time LED was updated

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxx";

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth);
}

void loop()
{
  Blynk.run();
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    if (ledState == LOW) {
      ledState = HIGH;
      Blynk.virtualWrite(VirtualPinA, 0);
      Blynk.virtualWrite(VirtualPinB, 1023);
    } else {
      ledState = LOW;
      Blynk.virtualWrite(VirtualPinA, 1023);
      Blynk.virtualWrite(VirtualPinB, 0);
    }
  }
}

Cheers,

Matthew.

2 Likes

Thank you @MDriver for posting the solution!

That isn’t nice. It should be documented.

Even better, give the user the option for minimum and maximum values as for the the Gauge.

1 Like

You could hack that by using the arduino map function.

WidgetLED led1(10); //объявляем светодиод, к примеру на 10 виртуальном пине.

В нужном месте управляем
led1.on();
или
led1.off();

Thanks for the input! I am using your code to know the connection status of the device for shared applications It works perfect