Is True/False interchangeable with High/Low?

Just hoping someone could help me with this query.

int LED = 1;
bool light = true;
digitalWrite(LED,light);

In my code above I have declared a boolean variable called "light" and assigned its value as true. I have then used this variable to write pin 1 to turn on a LED.

In this case, I am using a value of "true" to make and output "high". Is this ok and will arduino understand this? I have the same question regarding "false" and "low".

Thank you very much for any help you can provide.

It will work, only because both HIGH and true are defined as 1, while LOW and false are both defined as 0. Also, digitalWrite looks for a zero, or non-zero value, not just 0/LOW or 1/HIGH. It would, arguably, be better style-wise to do either:

if (light)
digitalWrite(LED, HIGH);
else
digitalWrite(LED, LOW);

or, equivalently

digitalWrite(LED, light ? HIGH : LOW);

But, what you have will always work as expected, and is widely used.

Regards,
Ray L.

rowleyrolls360:
Just hoping someone could help me with this query.

int LED = 1;
bool light = true;
digitalWrite(LED,light);

In my code above I have declared a boolean variable called "light" and assigned its value as true. I have then used this variable to write pin 1 to turn on a LED.

In this case, I am using a value of "true" to make and output "high". Is this ok and will arduino understand this? I have the same question regarding "false" and "low".

Thank you very much for any help you can provide.

The great thing about all of this stuff is ‘you’ can test things out to see what happens.
It only takes 20 seconds of your time.
Hey, you can even print the value of variables to the serial monitor to confirm a hypothesis.

It will work but the obvious question is why would you want to do what you ask ?

My advice would be to stick to conventional names for the constants/defines such as HIGH, LOW etc It makes the code and your intentions much more obvious

Incidentally, putting an LED on digital pin 1 of most Arduinos may not be sensible as it is used by the hardware serial interface