Logic 1 or 0 for Widget LED possible?

Hardware model - Wemos D1 mini & wifi
iOS latest version
Arduino IDE latest version.
Blynk servers
Latest Blynk library

Hi everyone,

I want to read the state of a physical pin (RELAY_Pin), and output that to my app LED (V6).

I can get it to work with:

byte output = digitalRead(RELAY_Pin);   //set "output" to the same state of relay output pin D6
  
 if (output == HIGH)
 {
  virtualLED.on();  
 }
  else
  virtualLED.off();

But is there a way to get this working:

 Blynk.virtualWrite(V6, digitalRead(RELAY_Pin));   //write 1 or 0 to pin V6, but need 0 or 255 for widget led

It only send 1 or 0, which are read on app as brightness levels from 0-255.

Thanks

byte output = digitalRead(RELAY_Pin);   //set "output" to the same state of relay output pin D6
  
 if (output == HIGH)
 {
   Blynk.virtualWrite(V6, 255);
 }
  else
{
   Blynk.virtualWrite(V6, 0);
}

Of even this… a bit of a hack, but it will work since 0 x 255 = 0 but 1 x 255 = 255 … wow, math is useful… but I still hate it :stuck_out_tongue:

 Blynk.virtualWrite(V6, digitalRead(RELAY_Pin)*255);   // write 255 or 0 to pin V6
1 Like

Cheers Gunner, that’s excellent.

I think I will go with

 Blynk.virtualWrite(V6, digitalRead(RELAY_Pin)*255);   // write 255 or 0 to pin V6

Nice and simple, should have been obvious really :smiley:

1 Like