Purpose
To build a traffic light.
Materials
Background Knowledge
Complete basic Microbit courses.
Bricks build-up
Software
4.7. Programming
Step 1
Click “Advanced” in the MakeCode drawer to see more choices.
n order to programme for the Ring:bit Bricks Pack, we need to add an extension. Click “Extensions” at the bottom of the drawer. Search “Ringbit” in the dialogue box to download it.
Note: If you met a tip indicating codebase will be deleted due to incompatibility, you may continue as the tips tell or build a new project.
Step 2
Drag the set strip to NeoPixel at pin with led as
to on start
, set the pin at P0 port. Initialize the strip in 3 LEDs and in RGB(GRB format).
Step 3
Click “Advanced” to choose “Functions” and click “Make a Function” as the picture shows below.
Step 4
Enter “Red LED lights on” and click “Done” to create a function, and create another two functions “Yellow LED lights on”, “Green LED lights on” in the same way.
Step 5
In the function of “Red LED lights on”, set the third LED in red and the other two in black; in “Yellow LED lights on”, set the second LED in yellow and the other two in black; in “Green LED lights on”, set the first LED in green and the other two in black.
Step 6
Set “red led lights on” function in “Forever”, and pause 3000ms; Set “yellow led lights on” function and pause 1000ms; set “green led lights on” and pause 3000ms.
Code
Link: https://makecode.microbit.org/_DdAU5d4kMJDh
You can also download it directly below:
Result
When power on, the red LED lights on for 3 seconds, then the yellow led in 1 second and the green one in 3 seconds at last.