Use of HIGH/LOW in virtualWrite()

I think I’ve encoutered a slight hickup with the interpretation of HIGH for LED Widgets on different platforms.
When using virtualWrite(V0, HIGH) on a Particle devices, the LED Widget does not come on (and I purposely don’t use the WidgetLED class to test exactly this behaviour).
The background seems to be that HIGH is defined differently on various platforms (sometimes as -1 other times as +1).

  int currentState = digitalRead(D0);
  virtualWrite(V0, currentState); // this doesn't switch the LED Widget in the app on even with D0 HIGH
  // but if I explicitly do
  virtualWrite(V0, currentState ? -1 : 0); 
  // the LED goes on in the app when D0 goes HIGH

So the best IMHO would be to alter the “backend” (Blynk servers or mobile apps, whereever the comparison happens) not to check for == HIGH but to check for != LOW to cater for all platforms, since all of the platforms known to me define LOW as 0.

That would also fit the standard C (and most other languages) translation of non-boolean values to boolean.
Any value that is non-zero will be mapped to boolean true and only 0 maps to boolean false.
So in order to compare an arbitrary value to true checking for != false is the safest bet.

Hello. LED works with 0 as LOW and 255 as HIGH. Please either use widgetLED.on(), off() or virtualWrite(V0, 0) and virtualWrite(V0, 255).

Doc -

It will not fit this standard. As LED also has brightness.


I see, I missed the “analog” (virtual PWM) nature of the LED widget - with this in mind things make more sense :blush: