Do true and false compile as the same value as HIGH and LOW?

marco_c:
Doing anything other than using the defined symbols is really bad coding practice, can lead to hard-to-find bugs and has the high potential of creating non-portable source code.

Nailed it! This is indeed the core of the issue.

marco_c:
Yes, digitalWrite(). I should have been explicit - it should have been designed with a boolean parameter..

It does make more sense and would offer much more flexibility in this context. HOWEVER, it would be a deviation from traditional C implementations for hardware programming. Consistency matters and keeps the learning curve down when transitioning between platforms.

On the 'Arduino NANO Every', the second argument to digitalWrite() and value returned by digitalRead() is no longer an 'int'. It is an 'enum' in "api/Common.h" named "PinStatus":

typedef enum {
  LOW     = 0,
  HIGH    = 1,
  CHANGE  = 2,
  FALLING = 3,
  RISING  = 4,
} PinStatus;

Note: The argument to pinMode() is also an enum:

typedef enum {
  INPUT           = 0x0,
  OUTPUT          = 0x1,
  INPUT_PULLUP    = 0x2,
  INPUT_PULLDOWN  = 0x3,
} PinMode;

I'm not sure what the implication is for interoperability between PinStatus and 'int' or 'bool'.

1 Like

johnwasser:
On the ‘Arduino NANO Every’, the second argument to digitalWrite() and value returned by digitalRead() is no longer an ‘int’. It is an ‘enum’ in “api/Common.h” named “PinStatus”:

typedef enum {

LOW = 0,
HIGH = 1,
CHANGE = 2,
FALLING = 3,
RISING = 4,
} PinStatus;




Note: The argument to pinMode() is also an enum:


typedef enum {
INPUT = 0x0,
OUTPUT = 0x1,
INPUT_PULLUP = 0x2,
INPUT_PULLDOWN = 0x3,
} PinMode;




I'm not sure what the implication is for interoperability between PinStatus and 'int' or 'bool'.

Can anyone tell me what “digitalWrite (pin, CHANGE)” does?

TheMemberFormerlyKnownAsAWOL:
Can anyone tell me what "digitalWrite (pin, CHANGE)" does?

That is intended for the attachInterrupt function, not digitalWrite. The use of an enum did initially break code that did not use HIGH / LOW.

TheMemberFormerlyKnownAsAWOL:
Can anyone tell me what "digitalWrite (pin, CHANGE)" does?

On the 'Arduino NANO Every' it toggles the output pin:

		/* Set output to value */
		if (val == LOW) { /* If LOW */
			port->OUTCLR = bit_mask;

		} else if (val == CHANGE) { /* If TOGGLE */
			port->OUTTGL = bit_mask;
									/* If HIGH OR  > TOGGLE  */
		} else {
			port->OUTSET = bit_mask;
		}

I like that enum return value … much more informative!