element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
microbit
  • Learn
  • Learning Center
  • STEM Academy
  • microbit
  • More
  • Cancel
microbit
micro:bit Blog 10 BBC micro:bit Projects in 10 Days: Day Two - Countdown Timer
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
microbit requires membership for participation - click to join
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: jlucas
  • Date Created: 3 Jun 2016 11:33 AM Date Created
  • Views 3801 views
  • Likes 20 likes
  • Comments 1 comment
  • micro:bit
  • bbc micro:bit
  • microbit
  • bbc_microbit
  • beginner micro:bit projects
  • bbc microbit
  • ten bbc micro:bit projects
  • beginner_microbit_projects
  • 10projects10days
Related
Recommended

10 BBC micro:bit Projects in 10 Days: Day Two - Countdown Timer

jlucas
jlucas
3 Jun 2016

About this project

 

This project utilises the BBC micro:bit's input buttons and introduces some more complex commands, giving pupils the opportunity to create a simple countdown timer on their device.

 

What you'll need

 

1 x BBC micro:bit

1 x Micro USB

1 x Computer or tablet

2 x AAA Batteries & Battery Holder

 

Project walk through

 

  • Go to the BBC micro:bit website, click 'create code' and begin a new Microsoft Block Editor project.

 

  • Click 'Variables' in the left-hand command menu and select the 'set [item] to...' tile. Drag this tile into the main coding space and click [item] to bring up a drop-down menu. Select 'rename variable' and change the title from 'item' to 'counter' in the command box which should appear. Click OK.

 

  • Now click 'Maths' in the command menu and find the small number block, which should have the figure 0 inside the text box as a default. Attach this to the 'set [counter] to...' tile, and change the number to 3.

image

  • Click 'Basics' on the command menu and drag the 'Show number' tile into the main coding space. Then under 'Variables' find a tile that simply says [Counter] and attach this to the 'Show number' tile like so...

 

image

  • Next, wrap the 'Show number' tile in a 'forever' loop (found under 'Basics') to tell your device to continuously display the number in the counter.

 

image

 

  • Click 'run' to test your program on the emulator. You should see the number three appear on the animated BBC micro:bit's LED array.

 

  • Now it's time to program the buttons. Under 'Inputs', find a tile that says 'On button [A] pressed do...'. Drag this into the main coding space, and attach a 'change [item] by [1] tile from the 'Variables' menu. Change [item] to [counter] to tell the program to increase the counter by one every time the 'A' button is pressed.

 

image

  • Drag in another 'on Button [A] pressed do...' tile, and change [A] to [B].

 

  • To tell the program to count down when the 'B' button is pressed, you need to create another variable. Under the 'Variables' dropdown, drag in another 'set [item] to...' tile and rename this tile to 'CountingDown' or similar. Connect it to your first 'set [counter] to' tile like so...

 

image

  • Under 'Logic' drag in a [False] tile and attach it to your 'set [CountingDown] to...' tile.

 

  • Right-click the 'set [CountingDown] to...' tile and select 'Duplicate' to clone this tile. Attach the clone to the 'on button [B] pressed do...' tile and change the value from 'false' to 'true'.

 

image

  • You have now told the program that whenever the 'B' button is pressed, the 'CountingDown' command should be set to true. The next step is to tell the program what we want it to do in this instance... in our case, this should prompt the program to start counting down backwards.

 

  • To do this, find the 'If...do' tile under the 'Logic' menu, and attach it to your forever loop.

 

  • Also under 'Logic', drag in an 'If [0] = [0]' tile and attach to the 'If...do' tile.

 

  • When you open the 'Variables' menu, you should see that you can now select a 'CountingDown' tile. Drag this into the first [0] on the 'If [0] = [0]' tile.

 

  • Replace the second [0] on the 'If [0] = [0]' tile with another 'true' tile from the 'Logic' menu.

 

image

 

  • Attach a 'Pause (ms) tile to your forever loop and set it to 1,000 milliseconds - i.e. one second.

 

  • Attach another 'change [item] by [1]' tile, and change [item] to [counter] and [1] to [-1].

 

image

 

  • Finally, you just need to tell the program to stop counting down when it reaches zero, otherwise it will continue into negative figures.

 

  • To do this, add another 'If...do' tile, and under 'if' attach another 'If [0] = [0]' tile, replace the first [0] with a 'counter' tile, and change '=' to '≤' - the symbol for 'less than or equal to'. This tells the program that an action is required when the countdown reaches zero.

 

  • Under 'do' attach a 'set [item] to' variable and change [item] to [CountingDown]. Now attach a [false] tile.

 

image

  • This tells the program that when the counter is equal or less than zero, the CountingDown command should be reset to false, essentially freezing the countdown.

 

  • Your full code should now look something like this...

 

image

 

  • Click 'run' to test the program with the BBC micro:bit emulator. Your countdown should start at 3. You can press the 'A' button to increase the figure, and the 'B' button to start the countdown. When the countdown reaches zero, it should stop.

 

  • Once you're happy that your code has worked, click 'compile' to download the script and drag it onto your BBC micro:bit. Congratulations! You've created a workable countdown timer!

 

Once your pupils have mastered the basics of creating a countdown timer, encourage them to experiment with the new commands they've learned to discover what else they can make it do. Let us know how they responded to the challenge in the comments section below...

  • Sign in to reply

Top Comments

  • volly
    volly over 8 years ago +3
    This is so easy to learn and do. I am of the opinion that this project will be a great success worldwide. I feel a bit nostalgic here. It reminds me of the days when we did coding on the then VIC 20 and…
  • volly
    volly over 8 years ago

    This is so easy to learn and do. I am of the opinion that this project will be a great success worldwide. I feel a bit nostalgic here. It reminds me of the days when we did coding on the then VIC 20 and commodore 64 as wel as the spectrum ZX81.

    Good Luck guys. great job  jlucas 10 BBC micro:bit Projects in 10 Days: Day Two - Countdown Timer

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube