My understanding is that LOW is a low but non-null value, i.e., not 0. If so, it can't be reliably used as an 'off' switch, can it?
Also, is it legal to code : int i = LOW; or int i =HIGH; ?
mb
My understanding is that LOW is a low but non-null value, i.e., not 0. If so, it can't be reliably used as an 'off' switch, can it?
Also, is it legal to code : int i = LOW; or int i =HIGH; ?
mb
No, you must use digital write if you need pins to go high or low. And while I'm not sure what level of reliability you're looking for, I can assure you that it certainly works fine for every need I've had.
ARe you talking about LOW the predefined variable or LOW in the sense of output voltage? It is unclear just what you are asking.
mummyboy:
My understanding is that LOW is a low but non-null value, i.e., not 0. If so, it can't be reliably used as an 'off' switch, can it?Also, is it legal to code : int i = LOW; or int i =HIGH; ?
mb
LOW is defined as 0. HIGH is defined as 1. Whether it can be reliably used as an 'off' switch depends what you mean by "used as an 'off' switch". Yes it is legal to assign the values LOW or HIGH to an int variable.
Yes, thanks for the answer. I had two question. One was whether 'LOW' could be assigned to a var, and I guess the answer is 'yes'. The second is whether it could be used reliably as a flag. Here the answer seems like 'maybe', which really means 'no'.
That question stems from the fact that the documentation states that LOW is a non-zero value when the pin is set to input, meaning it really cant be reliably used as an off flag. Can it? From the reference;
LOW
The meaning of LOW also has a different meaning depending on whether a pin is set to INPUT or OUTPUT. When a pin is configured as an INPUT with pinMode, and read with digitalRead, the microcontroller will report LOW if a voltage of 2 volts or less is present at the pin.
When a pin is configured to OUTPUT with pinMode, and set to LOW with digitalWrite, the pin is at 0 volts. In this state it can sink current, e.g. light an LED that is connected through a series resistor to, +5 volts, or to another pin configured as an output, and set to HIGH.
There are easy ways around it of course, but I for elegance it would be nice if HIGH = a postivie voltage and LOW = no voltage in which case it could be used reliably as a flag.
There is much confusion here.
No digital gate will measure a perfect 0 volts. It is guaranteed not to exceed a certain value that will be considered by a logic gate input to be "LOW".
This is a hardware problem.
In the software LOW is a constant value. It is used to set the digital output to the low state, and if a digital input has a voltage lower than the logic '0' threshold is returned to indicate that LOW state.
It will work perfectly fine as a "flag" to indicate that the logic input reads logical '0', even if the voltage on that gate is 0.1 V or so.
mummyboy:
The second is whether it could be used reliably as a flag. Here the answer seems like 'maybe', which really means 'no'.That question stems from the fact that the documentation states that LOW is a non-zero value when the pin is set to input, meaning it really cant be reliably used as an off flag. Can it?
What do you mean by 'a flag', and 'an off flag'? These terms could have many different meanings depending on the context, and we have no idea what you're trying to achieve here. Perhaps you should explain what you're trying to do, and then you might get some suggestions about the best way to do it.