Hello all!
I am trying to use an ‘int’ variable in a project for true/false values. I can’t get it to change from true to false, so I am probably doing something wrong.
I am using “myvalue = true;” to make it true, and “myvalue = false;” to make it false. I used “int myvalue = false;” at the top to specify it.
If I did something wrong, please let me know. I don’t need specific details, just the correct lines to change the values as needed. Thanks in advance!
true and false are values of variable type boolean or bool.
this is very ugly programming style to convert logic variable to other types. int variable can contain numbers from -32768 to 32767 and take in the chip memory 2 bytes for store it, so it is wasteful to using 2 bytes for 1 bit purpose. otherwise if your program has 16 boolean variables you can store they into one variable with help of bit-wise operators.
There’s nothing in your post that is obviously ‘wrong’, maybe you should post your complete code in CODE TAGS, then we can make a better guess at what you’re doing.
Are you "printing" the variables to the serial monitor? If so, false as an integer has a value of zero and it will print-out as 0. true will probably print-out as 1, but any non-zero value is true. You won't automatically see the words true & false.
The Boolean/Bool sounds like what I need after looking at the arduino reference, but which one should I use? It looks like Bool is recommended, but I don’t know what the difference is. Any pointers? Thanks again.