Programming-Arduino (1) - Pages-79
Programming-Arduino (1) - Pages-79
return f;
Notice how we have added .0 to the end of our constants. This ensures that the
compiler knows to treat them as float s rather than int s.
boolean
Boolean values are logical. They have a value that is either true or false.
In the C language, Boolean is spelled with a lowercase b, but in general use,
Boolean has an uppercase initial letter, as it is named after the mathematician
George Boole, who invented the Boolean logic that is crucial to computer
science.
You may not realize it, but you have already met Boolean values when we
were looking at the if command. The condition in an if statement, such as (count
== 20) , is actually an expression that yields a boolean result. The operator == is
called a comparison operator. Whereas + is an arithmetic operator that adds two
numbers together, == is a comparison operator that compares two numbers and
returns a value of either true or false.
You can define Boolean variables and use them as follows:
boolean tooBig = (x > 10);
if (tooBig)
x = 5;