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.
First, you need to create two variables. Click on the + symbol in the Startblock. Then you name one variable with countdown and the other with light.
Now set the start value from countdown to 10. As start value of light you take the value of the ambient light. You can find the block under Sensors.
Select the following block in the menu under Control to play your following code in an infinite loop.
In this section, you specify what it supposed to happen if the countdown placeholder has not yet reached 0. First select the if - do - else block from the menu under control to set the condition.
Now add the = block from the logic menu and change the equal sign to a greater-than sign. Then fill the block with the countdown variable and a 0 from the math section.
Next, select the set countdown block from the Variables menu. Add the + block from the math menu, change the + to a - symbol and fill it with the countdown variable and a 1**.
To display the countdown every time it counts down, take the show text block from the Action menu. Change text to characters to show each number individually and add the Countdown variable.
With the wait ms block from the menu item Control you can set how fast the countdown should count down.
Now enter what should happen when the countdown has reached 0. To prevent the screen from ringing continuously, insert the block clear screen from the action menu.
Now control the brightness sensor and let the value for the ambient light read out.
To do this, take the "set light" block from the Variables menu and add the get value lightsensor block from the sensors menu.
So that the alarm does not go off until the Calliope mini is in the light, take the " = " block from the logic menu and change the equals sign to a greater-than sign. Then insert the light variable and a suitable value. The value must be between 0 and 100. 0 is darkest and 100 is brightest.
Now you can insert different blocks for the alarm. Let the LED light up, play tones or display the text "Alarm".
Your alarm is now ready. Download your script and give it a try!
Turn on your Calliope mini and hide it in a cookie jar, for example. Close the lid before the countdown is over. Now the alarm is armed and goes off as soon as someone opens the jar.