If / Else statement flow block

This block will run one of 2 coding strips depending on the input value.

If / Else statement block can accept true or false input.

LEGO® Powered UP App coding example: Use a switch to change an instruction

Step 1: Add coding blocks

  • Flow block – Start
  • Flow block – Repeat instructions infinitely
  • Flow block – If / Else statement
  • Widget block – Toggle widget
  • Sound and light block – Play from the whistle sound library
  • Sound and light block – Play from the laser sound library

Please note: it is important that sound blocks from whistle and laser sound livbraries are placed as shown in the image.

Step 2: Add Canvas Toggle Button with address 0

Step 3:

  • Navigate to the Application control view
  • Observe that when the program starts, sound from the laser sound library is played
  • Press the Canvas Toggle Button (Toggle widget output value now is true)
  • Observe that after pressing the Canvas Toggle Button sound from the whistle sound library is played
  • Press the Canvas Toggle Button (Toggle widget output value now is false)
  • Observe that sound from the laser sound library is played

Back to Flow blocks page