This project uses Micro:bit single board as a digital counter, uses built-in button A to increase counting, built-in button B to decrease counting, programmed by MakeCode blocks. The project contains a few tasks, it is suitable for junior learners for basic programming exercise. Goals:
Fun playing with Micro:bit to catch button pressed events and button status input
Practice of basic if-else logic, multiple branches
Basic usage of Variable (numeric integer type)
START A BIT > Projects Library > This page
[ ] Simple: 30-60 minutes
[x] Moderate: 1-2 hours
[ ] Challenging: more than 2 hours
The estimation bases on average situation without unexpected troubleshooting, assuming that the student meets prerequisites. It only indicates rough time needed to complete this project, but not about technical difficulty, not covering discussion and sharing time. Here is a possible breakdown:
30 minutes: Task 1
40-50 minutes: Task 2
One should have prior knowledge
MakeCode by Microsoft, the programming tool
Purpose: Learn "on button A/B/A+B pressed" event triggered blocks, learn variable range guarding
Click-press button A to increase by 1, safe guard max as 9
Click-press button B to decrease by 1, safe guard min as 0, no minus count
Click-press button A+B together to reset counter as 0
Optional hinting and/or warning sound on different situations
Test with simulator in MakeCode and real target Micro:bit.
Test Case 1:
After starting or resetting, LED screen shows 0
Test Case 2.1:
Click-press button B, the counter should be increased by 1, the latest count is shown on LED screen.
Optionally, a short hinting sound is played on a valid count being increased.
Test Case 2.2:
Click-press button B many times until the counter reaches 9, then pressing button B should NOT change the counter any more, the count stays as max 9, shown on LED screen.
Optionally, a warning sound is played on an attempt to cross the max count.
Test Case 3.1:
Click-press button A, the counter should be decreased by 1, the latest count is shown on LED screen.
Optionally, a short hinting sound is played on a valid count being decreased.
Test Case 3.2:
Click-press button A many times until the counter reaches 0, then pressing button A should NOT change the counter any more, the count stays as min 0, shown on LED screen.
Optionally, a warning sound is played on an attempt to cross the min count.
Test Case 4:
Click-press button A+B together, the counter should be reset as 0, shown on LED screen.
Optionally, a warning sound is played on a successful resetting to 0.
Please submit your work to Google Classroom (here is a guide)
Catch button A/B/A+B pressing event triggering
Create a Variable to store the counting value
You can check this "Counter" project from microbit.org as an starting example, remember that the features we need here are more than that.
Anothe example "counter lesson" by MakeCode
Here is a solution with "FIX ME" challenge, if you need a draft as a start
Purpose: Learn using button A/B/A+B status, handle long pressing situation
Keep the same existing features of Task 1, adding below
When Long-pressing button B, the counter should keep increasing continuously, the latest count is shown on LED screen, when releasing button B, the increasing stops. Still max guarded as 9.
When Long-pressing button A, the counter should keep decreasing continuously, the latest count is shown on LED screen, when releasing button A, the decreasing stops. Still min guarded as 0.
Test with simulator in MakeCode and real target Micro:bit.
The Test Cases of Task 1 are still valid, adding below
Test Case 2.3:
When Long-pressing button B, the counter should keep increasing by 1 and show the new count on LED screen. The max 9 should still be guarded. When releasing button B, the increasing should stop.
Test Case 3.3:
When Long-pressing button A, the counter should keep decreasing by 1 and show the new count on LED screen. The min 0 should still be guarded. When releasing button A, the decreasing should stop.
Please submit your work to Google Classroom (here is a guide)
Catch button A/B/A+B pressing status
Create a Variable to store the counting value
Here is a solution with "FIX ME" challenge, if you need a draft as a start
Purpose: Creative task for your ideas, as an optional challenge task
Add different sound effects when increasing/decreasing the count, when hitting the max/min boundary.
If you notice, the button pressing is a little tricky, especially in Task 2, the button A+B will be missed sometimes, because when the if-evaluation happens, it's hard to ensure both button A and B are already pressed, there could be a little time-gap, you can improve the reactiveness by adding a little delay between checking the A and B status...
As you notice, starting from number 10, the LED screen displaying will have a scrolling, and it's slow animation. There are different ways to show a number, e.g. using the dots, and level bars. There are also some extensions for your exploration, search the extensions by keyword "number", you can get at least 2 interesting options.
Make a beep sound reminder if the counting result becomes full 10, 100, 1000, note that the beep should happen just once when hitting the full counting, but not keep beeping all the time.
Energy saving mode: When there is not many visitors coming, the counter will be idle for some time, so there is a need to save energy, don't display the counter figure all the time, instead, display it when shaking the Micro:bit, after 3 seconds, turn off the display
Purpose: Enhance basic knowledge understanding, reflect and summarize what we have learnt
How do we catch "button pressed" events? Is it triggered when pressing down, or releasing, or?
How do we get "button status" input? What is the value of it in the programming?
What are the difference between event triggering and status input?
Tips: Review knowledge from here if needed
This project is a good example to practice flow chart drawing! Use your own way to visualize how the programming controlling logic is done, by a free style drawing, so that your friends can follow this flow-chart to reproduce the programming.
Follow the tutor to take 5-10 minutes to review the questions and answers, correct some possible misunderstood issues or faults
Take 1-2 minutes to explore anything on the tools and the making flow, with curiosity, no matter how much prior knowledge you have, you should make
At least 1 interesting finding
At least 1 curious question
Here are some incomplete or buggy work by others, could you analyze and point out what are the matters?
An attempt for Task 1
An attempt for Task 1
An attempt for Task 1