Simplest way to turn boolean into a LED

Here the simplest way to light a LED from boolean variable:

boolean b = true;
digitalWrite(ledPin, b);

That has just save me a bunch of if…else statements. It makes for cleaner more readable code.

By the way, this is possible because “HIGH” and “true” are both defined as 1 in Arduino.h. So calling digitalWrite(pin, true) is the same as calling digitalWrite(pin, HIGH).

It’s probably not “best practices”, but I’m willing to take a chance this will never change ;-)

Leave a Reply

Your email address will not be published. Required fields are marked *