Skip to content

Logic

Use the Logic blocks to create if-then statements and comparison operations.

If statement block

An if statement does actions if a value is true. Add an else if or else statement to the if block by clicking Properties.

The else if statement gets checked if the first if statement fails. If all the else if statements fail, then the code does the else statement.

If statement with the comparator block

The comparator block returns true or false based on the comparison between two values.

Possible comparisons include:

  • Equal to =
  • Not equal to
  • Less than <
  • Less than or equal to
  • Greater than >
  • Greater than or equal to

Example 1

In this example, if the temperature of a sensor is greater than 25 °C, the speaker turns on.

Example 2

This example uses else if and else statements. The speaker turns on if the temperature is greater than 25 °C or you press Button 1. The speaker turns off if neither scenario is true.

If statement with the comparator and bitwise blocks

The bitwise block returns true or false based on whether two statements are both true (and) or if at least one of the statements is true (or).

Example 3

In this example, if the temperature of a sensor is greater than 25 °C or you press Button 1, the red R LED turns on.

Example 4

Adding to Example 3, if the temperature is less than 20 °C or you press Button 2, the blue B LED turns on. Otherwise, all the LEDs turn off.