This project makes more fun by using the knowledge of digital signal output and input, it's based on PJ011: Traffic Lights in Fixed Schedule , The program is made by MakeCode, the codes logic is simple, the implementation can be rather straightforward in a kids way, or can be guided to improve for very well structured logic using Variables/Functions/Loops. Goals:
Fun experience with Micro:bit's digital outputs & input, also as preparations for further creative projects
Experience with simple programming, inspire to start using Functions/Loops (Not a must, but motivate a feeling of the needs)
Enhance the understanding of digital signals, outputting and inputting digital signal with Micro:bit
START A BIT > Projects Library > This page
Here is an example of the result done by our student.
Wire the external LEDs using PIN 1, 2, 8. Some other PINs are also available, but not all are working due to duplex of other software functions, so please use PIN 1, 2, 8 as a starting here.
Wire external button to PIN
Always not-go except requested. This signs are facing the pedestrians, so it’s to be guiding the pedestrian, but not the vehicles.
Initially, as normal situation, the sign should be RED, so to let the vehicle drive smoothly without breaking
When a person comes, he/she presses the crossing request
after a while (3 sec), the sign becomes RED->YELLOW->GREEN, then the person walks across the road
after a while (5 sec), we assume that the pedestrian has finished, the sign becomes GREEN->YELLOW->RED again
[ ] 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
15-20 minutes: Hardware wiring
15-30 minutes: Programming, download and test
15-30 minutes: Optional, optimize the codes using Functions/Loops
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
Better to have done PJ001: External LED with Micro:bit and/or PJ011: Traffic Lights in Fixed Schedule
Function knowledge is not a must, but good to have prior ideas of what it is
1x Micro:bit V2 board , with USB cable
1x Green LED
1x Yellow LED
1x Red LED
3x resistors
A few jumping wires
This is what you need to build in a simplified graphical view.
Use the micro:bit pin breakout and breadboard to connect the components, you don’t need to use the exact holes in the breadboard as others, as long as the wiring path is correct.
NOTE:
The shcema picture's pin orders in the pin breakout is different from what we actually have, please find the correct pin to wire.
LED's 2 leads are polarized! Recognized the difference, wire the "-" leg towards GND.
Learn more: LED basic what/how.
Pay special attention to the 4 pins orders! And the wiring scheme with the pull-down resistor.
To output a digital signal to a specific pin
Advanced -> Pins ->
To get input from the button, you need to read in the digital signal from that pin
Advanced -> Pins ->
Not a must, but it's highly recommened to consider using Functions! You can do so as an optimization after creating a working prototype.
Advanced -> Functions
This snippet shows an example of the main logical flow.
This also example a good reason to use Functions as possible, it brings very friendly readability.
This snippet embedded in a function shows the full feature to turn on the green LED, play a warning sound, after a while and turn off it.
Not all other LEDs need the same feature, please follow your own design.
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
When you have got a working version, please consider
What could be the problem with the straightforward coding flow without functions?
What can we do to simplify/optimize it as a pro?
If you get a quick done, do you dare to take further challenges? Those challenging points are independent, not related to one another
Please consider optimize your program using Variables/Functions, you will be like a PRO with those!
The program requirement in this project is simple, the lights are not looping at all, but staying as not-go, except receiving a request. You can design a further version with general fixed looping schedule, but the button request will get a quick response as possible
Find out working copy as a MakeCode shared project.
Used as homework in LP2415: 4 Weeks Refreshing Package, 24w15
Used by demo for LP2517: Special Onboarding Workshop, 25w17