Arduino Language: Boolean variable

What is a boolean? How to use it in your program?

The boolean’s variable can take the values 0 (false) or 1 (true).

Each boolean variable use 1 Byte of memory :

  • False (0000 0000)
  • True (0000 0001)

Here is how we initialize a boolean:

The boolean can be use in if, for or while loop to express the condition we want to test.

We will see some examples:

Boolean expression

We will see now the different expressions that we can do with booleans.

a) Boolean expression OR

The boolean expression OR is used to verify if at least one of the both variables is at the state you wanted.

b) Boolean expression AND

The boolean expression AND can verify if the both variables are high state:

You can find others boolean expressions on our course on mathematics function.

How to reverse the state of a boolean?

We will see how to reverse the value (state) of the boolean with an exclamation point: