Pages: [1]   Go Down
Author Topic: Boolean variable becomes an int  (Read 622 times)
0 Members and 1 Guest are viewing this topic.
New Zealand
Offline Offline
Full Member
***
Karma: 1
Posts: 105
Just this guy you know.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26509
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

!
« Last Edit: March 10, 2012, 11:21:53 am by AWOL » Logged

"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.

New Jersey
Offline Offline
Faraday Member
**
Karma: 70
Posts: 3741
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

New Zealand
Offline Offline
Full Member
***
Karma: 1
Posts: 105
Just this guy you know.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Woops,  I was doing a bitwise
Code:
sensorValue =! sensorValue;
Totally works.  

Thanks AWOL

LOL Wildbill,  I guess it could only be outed by a null response.
« Last Edit: March 10, 2012, 08:48:42 am by hellonearthis » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26509
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I nearly wrote

!, !~

But I thought that too obscure.

The "!!" operation is useful for converting to a boolean.
« Last Edit: March 10, 2012, 09:07:10 am by AWOL » Logged

"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.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17303
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: