Home » Programacion » Facilino » Facilino Tutorial » Boolean logic instructions in Facilino

Boolean logic instructions in Facilino

In this post, we explain the use of Boolean logic instructions in Facilino.

What’s boolean logic?

Boolean logic is the set of relations between tow binary variables, that is, variables that can only take two possible values: true or false. Binary, a.k.a boolean, variables are very important within the context of digital electronic circuits because they are the basis to understand how digital electronic circuits work and also microcontrollers, microprocessors and programming in general.

What kind of instructions are available in Facilino

Relational operators

They allow stablishing the relation between to variables (any numeric type but Strings).

They allow us to set relations such as: equal to, non-equal to; lower than; lower or equal than; greater than; greater or equal than.

The result of comparing two numbers in a logic relational operation returns true or false depending on the compared numbers and the operation selected.

Binary operators

Facilino allows you to work with Boolean operations using to binary operands as inputs A and B, with values true (T) or false (F). Based on the Boolean operator selected, the resulting output will be different:

Operand A Operand B Operation “AND” Operation “OR” Operation “OR Excl.” Operation “OR Non-Excl.” Implication
F F F F F T T
F T F T T F T
T F F T T F F
T T T T F T T

Negation

Negation allows you to obtain the opposite value of a binary variable, which means that is a variable is true, the negation will return false and vice-versa.

True/False Constants

“True” or “False” constants can be used in the same ways as any binary variable, with the difference that they always return “true” or “false”, can’t be changed.

Examples

Example 1

In this example, we implement a basic logic operation based on an AND operation between two input values, corresponding to readings of push-buttons connected to digital inputs D2 and D3 of Arduino Nano. If both buttons are pushed, the built-in LED will be ON, otherwise, will be OFF.

 

Example 2

In this second example, we show how to use relational operators. In particular, we compare a secret number (random) with the one obtained through the console input. If both numbers are equal, then we show a congratulation message, otherwise, we invite the user to try it again.