Logical operators

There are several logical operators included in the Arduino programming language. These operators are the AND, OR and NOT operators. The NOT operator enables us to reverse a comparison operation. The AND and OR operators enable us to combine multiple comparison operators into one step. The following code shows how to use the logical operators:

(x > 5 && x < 10) // true if x is greater than 5 and less than 10
(x > 5 || x < 1) // true if x is greater than 5 or less than 1
!(x == y) // returns true if x is not equal to y

Now let's see how we can cast a variable.

Get Mastering Arduino now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.