We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.
The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ...
For more information on how Google's third-party cookies operate and handle your data, see: Google Privacy Policy
Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.
Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
About the Author
Les is a maker and trainer who has worked with the Raspberry Pi Foundation and the BBC to deliver computing training.
Timers are handy, they can time a boiled egg to perfection, help us take group photos, and be used to help rockets to launch. We shall make our own timer using a micro:bit, some crocodile clips and a speaker/headphones.
You will need to connect the headphones to the micro:bit as per this image.
For this project, we shall be using the Makecode Editor from makecode.microbit.org and we should already be comfortable copying code to our micro:bit.
From the Input, menu drag the “on button A pressed” block into the coding area.
Any code inside the block will be run when button A is pressed.
In the Variables, menu click on “Make a Variable” and call it “time” We shall use this variable to store the duration of our countdown.
From the Variables menu drag “set item to 0” block to the coding area.
Click on the arrow next to “item” and change to “time” then change 0 to 10.
We use a while true loop from loops and from Logic we connect a _ > _ block. Then from Variables, we drag time and place it in the left space and type 3 in the right space.
From the Basic menu, we use Show Number and use our time variable as the number. Then from Music, we use Play Tone and choose middle C to indicate a countdown is running.
Each time the countdown runs, it needs to pause for 1 second (pause (ms) from Basic) and then change the value of our time variable by -1.
Once the countdown reaches 3, we use another loop, and for 3 loops we change the tone to a higher note, to indicate that there is not much time left.
With the countdown reaching 0 we trigger a loop that will repeat 4 times. Each time it goes around, it will play a high G note really quickly. Just like an alarm clock!
Here is all of the code for this project.
We have learnt how to use loops, conditional tests, input, and make music with the micro:bit!
That’s it, now download the code to your micro:bit and when it has finished, press the A button to start the countdown!
Well done you have made your own countdown timer! Can you change the timer to time a boiled egg?