Exploration - Exploring LEDs (Student) (Physical Computing) (Micro - Bit) (Intro To Micro - Bit)
Exploration - Exploring LEDs (Student) (Physical Computing) (Micro - Bit) (Intro To Micro - Bit)
Exploring LEDs
Corresponding Material
1.2- Setting Up your micro:bit
Discussion
Now that we have run a few programs on our micro:bit devices, let’s learn how to control
individual LEDs. Explore the following commands to see what they do and then use these
commands to complete exercises of your own!
Needed Materials
(1) Micro:bit (1) USB cord
Class Exercise
1. Head to MakeCode.microbit.org
2. Click on New Project.
3. Develop programs by dragging commands from the center library or by typing them into
the editor yourself.
4. Test programs on the online simulator or run them to your micro:bit device by clicking the
Download button.
1 led.plot(0, 0)
2
Download the code to your micro:bit or run on the simulator and answer the following questions.
1) What do you see when you run the code on your micro:bit or simulator?
2) What do you think will happen if you change the numbers 0,0 to 1,0?
CodeHS | 1
Go into the code editor and replace the first 0 inside the parentheses with a 1. Download this
code to your micro:bit or run on the simulator.
1 led.plot(1, 0)
2
3) Was your hypothesis correct? What happened when you ran the code?
4) What do you think will happen if you change the numbers 1,0 to 0,1?
Go into the code editor and replace the second 0 inside the parentheses with a 1 and the first 1
back to 0. Download this code to your micro:bit or run on the simulator.
1 led.plot(0, 1)
2
5) Was your hypothesis correct? What happened when you ran the code?
6) Based on what you’ve noticed, label each box in the grid below with the coordinate point that
would light up each LED on your micro:bit. Feel free to try additional commands in the code
editor if you’re not sure of a coordinate value. The first box has been labeled for you.
0,0
CodeHS | 2
Code #2: Explore the unplot and pause commands
Type the following code into the code editor:
1 led.plot(2, 2)
2 basic.pause(1000)
3 led.unplot(2, 2)
Download the code to your micro:bit and answer the following questions.
1) What do you see when you run the code on your micro:bit or simulator?
2) What do you think will happen if you change the number inside the pause command from
1000 to 500?
Go into the code editor and replace the 1000 inside the pause command with a 500. Download
this code to your micro:bit or run on the simulator.
1 led.plot(2, 2)
2 basic.pause(500)
3 led.unplot(2, 2)
3) Was your hypothesis correct? What happened when you ran the code? What does the value
inside the pause command indicate?
4) What do you think will happen if the coordinates inside the plot and unplot commands do
not match?
CodeHS | 3
Go into the code editor and change the coordinates in the unplot command, as shown below.
Download this code to your micro:bit or run on the simulator.
1 led.plot(2, 2)
2 basic.pause(1000)
3 led.unplot(0, 2)
5) Was your hypothesis correct? What happened when you ran the code?
6) How do you think you could light more than one LED at once? Try out some commands in the
editor and once you’ve lit any 3 LEDs together, copy the code below:
1
2
3
7) Write a program that will turn any two LEDs on at once for 1 second (or 1000 milliseconds)
and then turn them both off.
1
2
3
4
5
1 basic.forever(function () {
2 led.plot(2, 2)
3 basic.pause(1000)
4 led.unplot(2, 2)
5 basic.pause(1000)
6 })
Download the code to your micro:bit or run on the simulator and answer the following questions.
CodeHS | 4
1) What do you see when you run the code on your micro:bit or simulator?
2) What do you think will happen if you remove the command on line 5?
Go into the code editor and remove line 5. Download this code to your micro:bit or run on the
simulator.
1 basic.forever(function () {
2 led.plot(2, 2)
3 basic.pause(1000)
4 led.unplot(2, 2)
5 })
3) Was your hypothesis correct? What happened when you ran the code? Why do you think the
program is functioning this way?
Conclusion Questions
1 2
.5 .25
2. How does the forever function affect the commands inside it? _____________________
CodeHS | 5