The digitalRead
method doesn't return a Boolean value. It returns an Integer.
From what I remember inside Arduino.h values of LOW
and HIGH
are defined as being simply Integer 0
and 1
.
#define HIGH 0x1
#define LOW 0x0
I think that was changed to an Enum called PinStatus
but Enum can be treated as an Integer.
This means that you have to store results of digitalRead
inside Integer variable.
int value = digitalRead(8);
It was designed that way to easily cast values between Integer and Boolean. By (very smart) design choice Integer value of 0
(LOW
) will be cast to false
and every other value (for example 1
or HIGH
) will be cast to true
.
The operator !
(Boolean NOT) can be used only with Boolean variables so the compiler needs to perform several "implicit casts". When it's smart enough it will assume you are know what you are doing and it will add the cast by itself.
By reading the error I see that the issue is happening when compiler tries to convert Boolean value into Integer. So this is implicitly evaluated correctly as a Boolean value
!digitalRead(pin_enable_line)
But when you try to put it inside a place for PinStatus you get the exception
cannot convert 'bool' to 'PinStatus'
Try adding an "explicit cast" to PinStatus:
digitalWrite(pin_enable_line, (PinStatus)!digitalRead(pin_enable_line));
It should fix the issue.
But I suggest splitting the code into several lines and adding a temporary variable. It makes debugging much easier. Trust the code optimizer that's built into the compiler. It will understand what you want to do and actual machine code will be the same.
digitalWrite(pin_enable_line, (digitalRead(pin_enable_line) == HIGH) ? LOW : HIGH);
(value is still LOW 0 and HIGH 1)