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