Go Down

Topic: Boolean variable becomes an int (Read 708 times) previous topic - next topic

hellonearthis

I am reading a digitalpin into a boolean value and then I not it and it becomes an integer value.

Code: [Select]
boolean sensorValue = digitalRead(2);  // returns 0 or 1
sensorValue =~ sensorValue; // Not operation and value becomes 255 or 254


I was hoping it would inverse the values, 0 would become 1 and 1 would become 0

AWOL

#1
Mar 10, 2012, 02:29 pm Last Edit: Mar 10, 2012, 05:21 pm by AWOL Reason: 1
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

wildbill

Ladies and gentlemen, the competition for the forum's shortest post is now over.

hellonearthis

#3
Mar 10, 2012, 02:39 pm Last Edit: Mar 10, 2012, 02:48 pm by hellonearthis Reason: 1
Woops,  I was doing a bitwise
Code: [Select]
sensorValue =! sensorValue;
Totally works.  

Thanks AWOL

LOL Wildbill,  I guess it could only be outed by a null response.

AWOL

#4
Mar 10, 2012, 02:50 pm Last Edit: Mar 10, 2012, 03:07 pm by AWOL Reason: 1
I nearly wrote

!, !~

But I thought that too obscure.

The "!!" operation is useful for converting to a boolean.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

retrolefty


Ladies and gentlemen, the competition for the forum's shortest post is now over.


LOL, and in the best tradition of the C language, short, concise, and very obscure.

Lefty

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy