Ep3-3: Countdown

  3 2 1 Go!

Let's create a musical countdown using the new micro:bit with sound!

1. From the 🔃 loops category in your toolbox, find the 🔃 for [index] from 0 to [4] loop and add it to your on start container.

2. Change your loop to count from 0 to 2.

💡 This means the loop will count 0-1-2 instead of what we want, which is 3-2-1. We will worry about this later!

3. From 🎧 Music, grab  🎧 play tone [Middle c] for [1 beat] [until don] and snap it into your empty for loop.

💡 Your simulator might start playing music. You can mute it if distracting

4. 1 beat is a little long. Use the dropdown to set the tone to play for 🎧 1/4 beat

5. From Basic, find show number [0] and snap it in at the bottom of your for loop.

6. From your for [index] from 0 to [2] loop condition, click and drag out the red index variable.

7. Use the index that you dragged out to replace the 0 in show number [0]

If you take a look at your simulator, you'll notice the micro:bit flashing 0-1-2. We want it to say 3-2-1! Let's learn a trick to change that.

8. From the Math category, snap [0] - [0] in to replace index in your show number [index] block.

💡 You should now have a greyed out index variable in your workspace. We'll use that in the next step.

9.  Pick up the greyed out index variable and snap it in to the right side of your [0] - [0] operator.

💡 Can't find index? Try moving your on start container to see if index is hiding behind it!

10. Set the left side of your [0] - [index] operator to 3.

💡 Why does this work? Every time we loop, our index variable will grow by 1 and our micro:bit will output: 3 -2 -1!

11. From Basic, grab show string ["Hello!"] and snap it into the very bottom of your on start container.

12. Replace Hello! with the word GO!

13. From the Music category, grab play tone [Middle C] for [1 beat] [until done] and place it above your show string ["GO!"] block and below your for loop.

💡 This will let your micro:bit play the sound and show GO! at the same time.

14. Set the tone to be Middle G.

💡 Middle G is also tone 392.

ปรับปรุงอีกหน่อยขอเป็น 9 8 7 6 5 4 3 2 1 Go!