Activities for loops
Let’s use a repeat loop to make a siren.
- From the INPUT Toolbox drawer, drag an on shake block onto the Workspace.
- From the LOOPS Toolbox drawer, drag a repeat loop onto the Workspace and place inside the on shake block.
- From the LIGHT Toolbox drawer, drag 2 show ring blocks onto the Workspace and place them inside the repeat loop.
- Change the colors of the show ring block lights to flash blue and red like a siren.
- From the MUSIC Toolbox drawer, drag a play sound block onto the Workspace and place inside the one shake block, above the repeat loop.
- In the play sound block, use the drop-down menu to change the sound to “siren”.
Click the SHAKE button on the Simulator on the left, and you can preview the Circuit Playground Express’ behavior.
Finally, practice using pause blocks. Place one after each show ring and change the duration of the pauses. Press SHAKE again in the Simulator, and you will see how different pause durations affect the siren you have made.
A final reminder on loops – if you are using sensor data, like from the sound, light, accelerometer, etc. then you probably want those blocks inside a forever loop because you want the Circuit Playground Express to be continuously checking whether it is being tilted, what the sound level is, etc. It’s possible you may only want to check sensor data on a specific input, like if a button is pressed, but usually you’ll need a forever loop.