Program a discolight for your next party.


30 mins

from 8 years on

In this exercise we'll use the Open Roberta editor. Make sure that you see this picture in the upper right corner of your programming environment. The editor can be found on our website at the top of the navigation bar: Let's start - Editor.

1creating variables

First, you create a variable. Click on the + symbol in the start block. Then you have got to name the variable, e. g. random.

2Infinite loop

In the menu under Control, select the following block to play your following code in an infinite loop.

3Setting conditions

First select the if - do block in the control menu to set the condition. Then add get... gesture? Block from the Sensors menu to control the position sensor. In the selection you now change upright to on the back.

Next, select the set random block from the variables menu. To these you add the random integer value between 1 and 100 block, from the math menu, change the 1 to a 0 and the 100 to a 4.
Now the value of the random variable is randomly set to a number from zero to four.

4Choosing colors

Now add another if - do block and add the block = from the logic menu to it. Now fill the block with the random variable, from the variables menu and a 0 to set the condition for the value zero of the variable.

You set the color for your first condition by inserting the turn LED on color" block from the Action** menu and selecting a color from the selection.

5More colors

You can duplicate this if-do block four times. To do so, right click on the if - do block and choose copy. For the other random numbers 1-4 of your duplicated blocks you can now choose the colors. Do the following in each of the 4 blocks:

  1. Change the random number.
  2. Choose a color.
  3. Put your blocks together.

To make the colors change slower, you can add a pause at the end of your infinite loop. For this you use the wait ms block, which you find under control. Try different waiting periods.

Done - download your script now and give it a try!

7For pros

You can use even more colors by increasing the random numbers: In the block of random integer values between 0 and 4 you can enter a larger number. Then you have to create more *if - do blocks, for which you can set the LED colors.

Hier findest du die fertige Datei!

Dieses Programm kann direkt im Editor geöffnet werden.