can someone tell me or explain how to use virtual pin in blynk? example. using virtual pin on led’s with connection to digital pins. ( turning digital pins will turn the led also using the virtual pins) can someone show me the code.
If you understand your requirement correctly, you want to use virtual pin and turn on/off LED on digital pins like arduino etc? If yes, below code does the same. You need to use virtual V0 on app and it turns on LED on digital pin 13. Hope this helps!
BLYNK_WRITE(V0)
{
int virtualPin0 = param.asInt(); // assigning incoming value from pin V0 to a variable
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
if (virtualPin0 == 1)
{
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
}
thanks for the reply. but i was asking on how to turn on the led(inside the blynk app) when the button is turn on or in HIGH state.
the circled part is the led/s. when the button d1 d2 and d0 is to be turned on. so should the led d1 d2 and d0 using the virtual pins.
you need to use WidgetLED like below
WidgetLED led1(V0);
if (your condition)
{
led1.on();
}
else
{
led1.off();
}
should i insert the code directly inside the loop? or should i create another void then insert it on the loop?
The best practice is to avoid keeping your code inside the loop. Please use another void.
@jillbert we have a bunch of ready examples for that. Please have a look here (don’t forget to read sketch comments for better understanding)
tnx sir. so much. code already working. TY!