This project helps to build basic knowledge of the programming interface of Micro:bit's built-in LED screen, it helps to understand how to control a single point as on/off in the LED matrix, adding some fun by spawning random blinking dot, and changing blinking frequency by button A/B, the challenge part further makes the dot moving by gesture control. The project contains a few tricky issues that need serious engineering practices to ensure a reliable and stable working result. Goals:
Coordinates of LED matrix, programming interface to control a single dot
Practice using multiple Variables
Practice using Functions
Concept of frequency Hz, and convert to time period
Serious engineering mindset and careful practices
START A BIT > Projects Library > This page
A demo of the result, by the tutor
This project uses 1 Micro:bit board with a USB cable, nothing else needed.
When powering up, randomly light up a dot on the screen, it blinks in 1 Hz frequency
Press button A to increase the blinking frequency, the max is 10 Hz, if already reached the max Hz, sound a warning
Press button B to reduce the blinking frequency, the min is allowed to be "0 Hz", which implies "no blinking at all" in our case, if already reached the "0 Hz", sound a warning
Press button A+B to change the position randomly, but keeping the current blinking frequency
[ ] 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:
5 minutes: Understand requirement and solution, collect materials
10-15 minutes: Task 1: Create A Random Dot Blinking in 1 Hz
15-20 minutes: Task 2: Change Blinking Hz by Button A/B
10-15 minutes: Task 3: Button A+B to Change Random Position
The challenge topic is not included in effort estimation, it could take extra 30-45 minutes for that part.
One should have prior knowledge
Micro:bit V2 board: Know what they are, better to have prior experience with it
MakeCode by Microsoft, the programming tool, better to have prior experience using it with Micro:bit
Basic knowledge of Variables, Functions
1x Micro:bit V2 board , with USB cable
Micro:bit LED screen has 25 LED arranged in a 5x5 grid.
Use (x,y) coordinates to specify a particular LED, x is the horizontal position (0,1,2,3,4) y is the vertical position (0, 1, 2, 3, 4).
Use plot and unplot to turn a LED on or off, or toggle to flip the state.
More info here from MakeCode document (link)
Not all blocks are used, pick that you want
plot to draw a point
unplot to erase a point
toggle is to flip over the state of the point
Led ->
Led ->
Led ->
"Frequency" (Wikipedia) is about how often an event happens periodically.
"Hertz"(Wikipedia) measures frequency, is defined as how many times this periodic event happens per second.
1 Hz => repeats 1 time per second => Slower
2 Hz => repeats 2 times per second
10 Hz => repeats 10 times per second => Faster
Which one is correct?
If not, what is the matter?
basic.pause(1 / blinking_hz / 2 * 1000)
basic.pause(1 / blinking_hz * 1000)
basic.pause(1 / blinking_hz / 2
basic.pause(1 / blinking_hz / 2 * 1000)
Divided by 0 when blinking_hz becomes 0
This is "illegal/invalid" operation in math or computer, just don't do it!
"Hertz" in Wikipedia: It is used only in the case of periodic events.
Some saying: Zero hertz means zero cycles per second, which means nothing is changing.
Some saying: Zero Hertz is a frequency that represents a complete absence of periodic oscillation. It means that there is no repeating pattern in the waveform and it is just a constant value.
Let's say:
We know "0 Hz" is confusing definition, the meaning might differs for specific cases (sound, wave, light, electrical signals, etc.)
We allow blinking_hz to be 0
We agree that "0 Hz" implies "no blinking at all", i.e. the LED dot is ON permanently.
because it make natural sense for our use case, when blinking_hz becomes lower and lower, we just feel the blinking becomes slower and slower, then we reasonably want it to be constantly ON if blinking_hz becomes even lower near to, or as, 0
You need 3 variables, 2 functions.
Please figure out the implementations of those 2 functions, then you are done, test it working!
The same structure as above, but using "toggle" to FLIP the status of the dot.
If it was ON, then it'll be flipped as OFF
If it was OFF, then it'll be flipped as ON
Please use the good practice of variables modification, be responsible and efficient.
Blinking Hz must be in range 0~10.
Button A part here, please figure out button B
Good to add "serial write" to send the real time value of a variable from the Micro:bit board to your PC, for debugging purpose.
0 Hz means no any blinking, the dot must be permanently on.
And you should be careful about the math problem of "division by 0"!
One solution with
plot-unplot
Another solution with
toggle
You might think like this to just change the x and y value as easy done... Test it to see what will happen, is it really working as expected?
What could be buggy? How to fix?
Use gesture(tilt left/right, logo up/down) to move the blinking dot to left/right/up/down.
When the dot hits the edge, warn a sound.
There are 2 relevant blocks to capture gesture, either will work, but a little different, feel free to try out!
Remember to keep guard of the variable changing, do not exceed the range of the LED (x, y) coordinate!
Since position change is used multiple times in different places, it's important to "unplot" the old point before changing to the new (x,y) position, it's a good idea to optimize the position change by a function like this.
Try to improve your code by this way. This makes your code structure neater and safer (more professional).
Stand in front of the class, share with your group what you have made, please cover important points
Tell what it is your product
Demonstrate how it works
Explain how it works
Share with your group about
What troubles you met
How you analyze
How you get help
How you solve it
What you have learnt
Find out working copy as a MakeCode shared project.