digitalWrite(13, on ? HIGH : LOW);
It was in the IRrelay example.What does the ? do and the : with both LOW & HIGH.
digitalWrite(13, on ? HIGH : LOW);
It was in the IRrelay example.What does the ? do and the : with both LOW & HIGH.
It's the functional equivelent to this:
if (on)
digitalWrite(13, HIGH);
else
digitalWrite(13, LOW);
on is probably a boolean (either true or false) or an int either 1 or 0, so it is equivalent to:
digitalWrite(13, on);
guix:
on is probably a boolean (either true or false) or an int either 1 or 0, so it is equivalent to:digitalWrite(13, on);
That code makes the assumption that HIGH and LOW are the same values as true and false. It just happens to be so in this case, but as a general rule it's best to avoid making that sort of assumption - the original implementation is preferable IMO.
That code makes the assumption that HIGH and LOW are the same values as true and false.
I don't think it does.
Last time I looked at the source of digitalWrite, it very specifically incorporated the C convention of zero / non-zero as meaning LOW / HIGH.
What does the ? do and the : with both LOW & HIGH.
If variable "on" has any value other than 0, set the pin. Otherwise (when "on" is 0), clear the pin.