Skip to main content
added 8 characters in body
Source Link
Filip Franik
  • 1.3k
  • 1
  • 8
  • 22

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 IntegerPinStatus:

digitalWrite(pin_enable_line, (intPinStatus)!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.

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 Integer:

digitalWrite(pin_enable_line, (int)!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.

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.

added 7 characters in body
Source Link
Filip Franik
  • 1.3k
  • 1
  • 8
  • 22

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 Integer:

digitalWrite(pin_enable_line, (int)!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 optimizedoptimizer that's built into the compiler. It will understand what you want to do and actual machine code will be the same.

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 Integer:

digitalWrite(pin_enable_line, (int)!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 optimized built into the compiler. It will understand what you want to do and actual machine code will be the same.

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 Integer:

digitalWrite(pin_enable_line, (int)!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.

edited body
Source Link
Filip Franik
  • 1.3k
  • 1
  • 8
  • 22

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 "Implicit"explicit cast" to Integer:

digitalWrite(pin_enable_line, (int)!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 optimized built into the compiler. It will understand what you want to do and actual machine code will be the same.

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 "Implicit cast" to Integer:

digitalWrite(pin_enable_line, (int)!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 optimized built into the compiler. It will understand what you want to do and actual machine code will be the same.

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 Integer:

digitalWrite(pin_enable_line, (int)!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 optimized built into the compiler. It will understand what you want to do and actual machine code will be the same.

added 313 characters in body
Source Link
Filip Franik
  • 1.3k
  • 1
  • 8
  • 22
Loading
edited body
Source Link
Filip Franik
  • 1.3k
  • 1
  • 8
  • 22
Loading
Source Link
Filip Franik
  • 1.3k
  • 1
  • 8
  • 22
Loading