I have an Arduino and I am wondering exactly what HIGH
and LOW
mean, as far as actual values go... Are they signed int
s? unsigned int
s? unsigned char
s? What are their values? I am guessing that HIGH
and LOW
are probably unsigned int
s with all of the bits set to 1 and 0 respectively, but I'm not sure. I would like to be able to do bitwise operations using HIGH
and LOW
, or pass values other than HIGH
or LOW
to digitalWrite
. Also, how would I cast an integer to HIGH
or LOW
so I could do this?
5 Answers
Have a look at hardware/arduino/cores/arduino/Arduino.h
(at least in Arduino 1.0.1 software), lines 18 and 19:
#define HIGH 0x1
#define LOW 0x0
Meaning, these defines being hexadecimal integer values, you can do whatever bitwise operations you want with them - how much sense that will make, however, is not really clear to me at the moment. Also bear in mind that these values might be subject to change at a later time - which would make bitwise operations on them even more unwise.

- 11,056
- 4
- 42
- 71
If you want to pass other values to digitalWrite() you can have a look at the function prototype
void digitalWrite(uint8_t, uint8_t);
So any integer value (well, 0 through 255) would work. No idea what the behavior of digitalWrite() could be if you passed it a value other than HIGH and LOW.
Since HIGH and LOW are simply defined constants, you can't cast an integer to them (nor would that operation make sense). It appears that you could use an integer anywhere that HIGH and LOW was expected.
Actually doing this is a bad idea though, for lots of reasons - the definitions of HIGH and LOW could change (unlikely but possible) and it doesn't make sense from a type perspective. Instead, you should use logic in your program to determine whether HIGH or LOW should be passed to the function call, and then actually pass the constant.

- 638
- 4
- 8
-
1actually. TRUE and FALSE are not defined anywhere for arduino as far as I know, only HIGH and LOW and true and false... (HIGH=true, LOW=false) – codeling Sep 14 '12 at 23:05
-
Answer above states defined constants. – Void Star Sep 14 '12 at 23:47
To add my two cents to codeling's answer:
Lines 18--25 of Arduino.h
(1.0) are:
#define HIGH 0x1
#define LOW 0x0
#define INPUT 0x0
#define OUTPUT 0x1
#define true 0x1
#define false 0x0
Therefore, HIGH <==> OUTPUT <==> true <==> 0x1
and LOW <==> INPUT <==> false <==> 0x0
.
Then, HIGH <==> !LOW
and LOW <==> !HIGH
...

- 30,738
- 21
- 105
- 131

- 611
- 6
- 4
-
2It's so weird that INPUT/OUTPUT are completely reversed (from "normal" development using AVR-GCC, anyway). One of my favorite things about AVR mcu's was that "1" looked like an "I" (for input), and "0" looked like an "O" for output, which made it super easy to remember. – BrainSlugs83 Mar 29 '15 at 17:19
The first argument to digitalWrite() is a pin number.
The second argument to digitalWrite() will either:
- write a HIGH (3.3 or 5 V) or LOW (0 V) to a BINARY OUTPUT or
- enable (HIGH) or disable (LOW) the internal pullup on a BINARY INPUT.
Bitwise operations for either argument make no sense. Perhaps you need to use analogWite()?
See the documentation: digitalWrite() Constants

- 30,738
- 21
- 105
- 131

- 927
- 1
- 11
- 15
-
1HIGH, AND LOW are just numbers (1, and 0) respectively. Bitwise operations on them make total sense. -- As for the behavior of digitalWrite, the second argument is an unsigned 8-bit integer which is treated as a boolean -- so anything non-zero should be treated as HIGH. – BrainSlugs83 Mar 29 '15 at 17:23
About INPUT and OUTPUT: OUTPUT is 1 because DDRD has to be set to 1 to set an I/O to output.

- 1
-
1Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 16 '23 at 00:02