This project uses PJ001: External LED with Micro:bit hardware setup, it uses Micro:bit same built-in button A to alternately turn on/off external LED connected to pin 1, programmed by MakeCode blocks. This project uses built-in button A to trigger the external LED on/off, in this case, the button is already de-bounced by Micro:bit. Goals:
Consolidate knowledge of digital output, how to use it with Micro:bit
Variable basic understanding, Boolean type variable and usage
Hardware: LED basic, pins and wiring
Software: Boolean type logic, if-else logic
START A BIT > Projects Library > This page
Here is an example of the successful result.
Hardware wiring is exactly the same as PJ001.
Use Micro:bit built-in button A as digital signal input from user
Use Micro:bit pin 1 as digital signal output to drive external LED
Press the same button A to alternately turn on and off the external LED
[x] Simple: 30-60 minutes
[ ] 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: Hardware setup and wiring
10-15 minutes: Programming, testing
One should have prior knowledge
Micro:bit V2 board, Micro:bit pin breakout board, Breadboard: Know what they are, better to have prior experience using them
MakeCode by Microsoft, the programming tool, better to have prior experience using it with Micro:bit
LED basic what/how: Should be able to identify and connect the legs correctly
Resistor basic what/how: Just need to know what it is, better to know why we need it here, no need to know how to read the color rings
It's better to have done PJ001: External LED with Micro:bit as a base
1x Micro:bit V2 board , with USB cable
1x breadboard
1x LED, random color
1x resistor (220 Ω or 120 Ω, the tutor distributes the available materials)
Some jumping wires
This project reuses the hardware setup from PJ001: External LED with Micro:bit, please visit the PJ001 page for detailed information.
You need a variable to help remembering the current status of LED, use "Make a variable... ", give it a name, e.g. "is_led_on", then you see 3 blocks available to manipulate this new variable.
We will use this variable as Boolean type (true/false), the "0" or "1" shown here is not relevant. Use the logic Boolean true/false block to fill in this occupancy.
Variables -> Make a variable...
To link the logic, you need a if-else block and logic Boolen true/false value blocks.
Optionally, the "not" block is also very useful when you want to flip the Boolean value to the opposite side.
Logic -> Conditionals ->
Logic -> Boolean ->
Logic -> Boolean ->
To drive digital signal output so to turn on/off the external LED, use this, remember to change to "digital write pin p1 to 1" or "digital write pin p1 to 0"
Advanced -> Pins ->
This is an event triggered block, available to capture button events A/B/A+B
Input ->
You also need both or either blocks to help making things work. They are normally prepared, just use it when needed.
Basic ->
Basic ->
Keep in mind that initialization is always a good point to think about in programming. At the beginning, you need to tell the variable what value it helps you to remember as a starting, and it's also good idea to set LED as off as a clear start point.
This bunch of code shows how to turn on or off LED on pin 1, based on the "is_led_on" status.
Now, next thing you can guess is to update your variable "is_led_on" with the current real status of LED, i.e. "Flip is_led_on value".
This bunch of code shows how to turn on or off LED on pin 1, based on the "is_led_on" status.
Now, next thing you can guess is to update your variable "is_led_on" with the current real status of LED, i.e. "Flip is_led_on value".
This is a common sense of flow to make the "is_led_on" variable flipping to the opposite side.
The "not" operation on a Boolean variable makes it flip to the opposite side! This is a master piece of the simplest solution!
This optional part covers further competence development, in terms of testing, troubleshooting, analysis, documentation, flow chart diagrams practices, etc.
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
Use your own way to visualize how the hardware components are connected by a free style drawing.
Visualize clearly the wiring path, mark clearly the pins and end points
So that your friends can follow this drawing to correctly reproduce the hardware setup
Any kind of children style drawing is OK! Here are some examples.
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.
You might be interested to know what is "flow chart", click to learn more, but so far, it's not needed to be that serious, just draw something that can help you explain to your friends how the programming is made.
Tell us what is variable and what is boolean type variable in your own way, explain how this variable helps you in this project.
What if you forget "on start" setting to initialize the variable?
What if you forget to update the "is_led_on" Boolean variable (flip to its opposite side) after turning on/off the LED?
These questions are out of scope for this project, but great to think about them, ask and discuss if you have enough effort
Logical "not" operation on Boolean type variable to flip its value, if this is difficult for you to understand, then park it here, not a mandatory point for now.
How to read the resistor value by the color rings?
If using external button and "read digital pin..." method to do the similar task to alternately turn on/off external LED, then we will meet the classic press-button bouncy problem... if you have questions on this, it's not a must to understand for now...
If you get a quick done, do you dare to take further challenges? Those challenging points are independent, not related to one another
(This project doesn't really have a further challenge yet)
Find out a working copy as a MakeCode shared project