How to Make a Counter with microbit
When we have boarded airplane, we often encounter a situation like this: a beautiful stewardess carrying a small silver box keeps press it while passing by. She is murmuring:1,2,3,4,5,6...... You must guessed it--she is counting the total number of people sitting on the airplane. And the small silver box on her hand is a mechanical counter. Today, we are going to make an electronic one with BBC micro:bit.
First, we have to know what function we want to realize with this electronic counter. I have a simple conclusion for it.
Basic Requirement
1.Press button “A” , counter number minus 1;
2.Press button “B” , counter number plus 1 ;
3.Press button “A”、“B” together, counter number become 0.
2.Press button “B” , counter number plus 1 ;
3.Press button “A”、“B” together, counter number become 0.
Material
1 x micro:bit
1 x USB
1 x USB
You might wondering how can we make an electronic counter with a micro:bit board and a USB cable only. Don’t worry! It is very easy and simple. You will learn it soon.
After we gathered our materials, we have to program for it. Connect micro:bit board with your computer. Then click this link: https://makecode.microbit.org/# to open programming interface. We are going to use Block method to do programming. You can read the following steps to learn how to program.
Step 1
To start, we build a new variable named “counter” and set “0” as the initial value .
Step 2
Write code for press button “A”、”B” and “A+B” separately.
1.Press button “A”:
The function of button “A” is deduct count number. We all know that no matter what we count, the count number would not be under 0. If negative number appears, then there must be something wrong. In order to avoid this mistake, we have to set counter judgment “≥ 1” in our program. If “counter≥1”, then press button “A”, it will deduct 1 automatically.
2.Press button “B”:
Every press increases 1 counter number.
3.Press button “A+B”:
Press button “A” and “B” together, the counter number become 0. Then you can start a new count.
Step 3
After we finished button code writing, we have to use 5*5LED screen to show the counter number.
We can directly drag block “show number” under button code. Then the count number on screen will change according to the variable counter number.
You can see the whole program code in the following picture:
You can see the whole program code in the following picture:
You can rewrite code by yourself to enjoy programming by dragging different blocks within block editor. It is very simple and easy just like playing bricks.Or you can download code directly into your micro:bit through the link below:
Now, let’s download the whole program code into micro:bit and see what will happen.
With this counter, we can know how many books we have placed on our book shelf, how many plates in the kitchen, how many eggs left in our fridge. Even, we can use it to count a basketball game. This tiny electronic is really powerful.
With this counter, we can know how many books we have placed on our book shelf, how many plates in the kitchen, how many eggs left in our fridge. Even, we can use it to count a basketball game. This tiny electronic is really powerful.
Question
How to revise our program if we want to limit the maximum value of counter? Your further discussion is welcomed!