Micro Bit English
Micro Bit English
in
elementary school
33 M o d e l s
odels
Contents
Preface p. 3
Preparation p. 4
Function test p. 5
Editor p. 6
Save p. 6
Load p. 7
Blocks/Commands p. 7
Traffic light p. 8
Pedestrian signal with request button p. 9
Actuators/sensors p. 10
Buttons p. 10
LED p. 11
Pedestrian signal with flashing light p. 14
Hand dryer p. 15
Hand dryer with light barrier p. 16
Phototransistor p. 17
Motor p. 17
Hand dryer with LED display p. 20
Barrier p. 21
Parking garage barrier p. 22
Parking garage barrier with optical display p. 28
Possible errors p. 30
2
Preface
Hello!
Allow me to introduce myself - my
name is RoBo, and I’ll be helping you
as you work through the different
exercises.
Before you start with the exercises, there are a few basic ground
rules I need to explain.
Sincerely, RoBo
3
Preparation
Before you begin building the models and start programming, you
need to make a few preparations.
Start your web browser and open the program editor under
https://makecode.microbit.org
Functional test
Click the selection “Basic”. All commands from this block area will
appear in this block.
Drag the command into the empty area for the command “on start”.
4
When you click the individual LEDs, they will be activated and
displayed in the simulation.
Create a plus sign using the LEDs. Your working screen should
look like the one shown on the image.
5
Editor
Programming screen
Simulation
Programming commands
Undo
Save
Once you have completed a project, you have to save it. To do so,
select the “Save” button.
6
Click the arrow beside “Save” and then “Save as”.
However, you can also select the “Import” button. A context menu
will appear. Here, select “Import file”.
OK, now that you are done with that, you can try out your first model.
7
Traffic light
What will make your traffic light unique is that it will be switched
on by a button located on the mast.
The next time you are going home from school or taking a walk with
your parents, and you pass a pedestrian signal, take a look at it.
Simply write the answers down on a sheet of paper, then use them
later when you write your own programming commands.
Important: Before you start operating real models, you can always
test out your programs first using the programming simulator.
8
Pedestrian signal with request button
Next, start the “makecode” editor. You will already be familiar with
the screen that appears.
9
Actuators Hang on, now I need to explain the two electrical components
installed in the model to you. These are called “actuators”
Sensors or “sensors”, depending on their function.
Electrical
components
Actuators Sensors
Buttons are called touch sensors. If you press the red button, a
contact is moved mechanically within the housing and current flows
between connections 1 and 3. At the same time, contact between
connections 1 and 2 is interrupted. This means you can add the button
to your model as a switch.
Buttons
Circuit symbols Toggles
3
Normally
3
1
Normally
1
open 2 2 closed
The name LED stands for light-emitting diode. When electrical current
flows through the diode (forward direction), it emits light.
10
There are two LED modules in the construction kit. You can use them
as normal lamps, or use them later as signal transducers on a light
barrier. Circuit symbols
I will explain the other components to you when we get to the specific
tasks.
Now we’ve explained everything important and you can start with
your first program.
Let’s start in sequence. Each program you write always starts with
a “Start” command.
In the task, this means that the program is started by pressing the A
button on the micro:bit.
You use the command “on button … pressed” from the “Input”
block. Drag the command to your programming screen.
11
The blocks “on start” and “forever” are not required and can be
deleted. Right click the command and select “Delete Blocks” in the
context menu.
Next, you will create a program section with the command “on pin
P1 released” embedded from the “Input” block. Drag the command
to your working screen.
12
Send the sub-program to the micro:bit (see page 5).
Press the A button on the micro:bit as well. The red lamp will light up.
After 2 seconds, the red lamp will go out and P 13 will go out in the
simulation. The green lamp or Pin 12 will switch on.
If you press the pedestrian button on the traffic
light mast, the red lamp will go out and the green
lamp will go on.
13
Pedestrian signal with flashing light
Let's start the second part of the task.
trafficlight2.hex
After the 5 seconds is complete, the green lamp should flash three
times. The flashing frequency is 1 second. Then the light is switched
to red.
Here, you will use the command “repeat x times” from the “Loops”
block. Dock it after the 5 second
pause.
Now the second part of the task is programmed. Save the file on your
computer. Test it out virtually, then test it a second time on your model.
14
Hand dryer
You definitely don't have something like this in your bathroom at home.
You have a big towel hanging on a hook. But in public bathrooms, like
the bathroom at your school or a restroom at a restaurant, you will
often see electric blowers mounted on the wall that blow out hot air
to dry your hands.
Sincerely, RoBo
15
Hand dryer with light barrier
fan1.hex
Program the hand dryer so that when a user reaches through the
light barrier, the motor with propeller starts up. When they take
their hand back out of the light barrier, the motor must stop.
16
To create the light barrier you will need to switch the fan
motor on and off, you will need the LED you have already
used, as well as a phototransistor.
Phototransistor
You have already started the Editor and can start with the “on start”
block. It is already shown on the screen, so you can go ahead and
add another command.
As you can see from the building instructions, the motor is connected
to “Pin16” and “Pin15”. Pin16 should be the negative terminal, and
Pin15 the positive terminal. Because of this, Pin16 is set to “0” on
start. The LED is connected to Pin8. Since it should
be illuminated forever, you can add the command
you need to the “on start” part of the program.
17
You need “forever” for the rest of the program. This command is also
already on your programming screen.
Digital Before you continue, I need to explain two terms to you: “digital”
and “analogue”. What do they mean?
Analogue
Digital values can only have two conditions, 0 or 1, yes or no. Here’s
an example: A lamp is on (1) or off (0).
First, add the command “digital write pin ….”. Switch “P0” to “P1”,
since you have connected the phototransistor to this
pin.
Now you need a command that queries “If an event is true, then
action1 should be carried out. If this is not the case (else), action2
should be carried out”.
You can find this command under the “Logic” block, under “if true
then --- else”. Dock this command in your program.
18
I have already written the whole program for you and discovered
that the photoconductive cell switches at an analogue value of
500. This value must be queried in the program. You can find the
command under the “Logic” block.
Now add the query “if “analog read pin P1” “< smaller” “500””
to your program.
19
Hand dryer with LED display
fan2.hex
There is an LED matrix on your micro:bit with 25 LEDs. You should
now use it to display the current switching status of the motor. If
the motor is running, an + should appear. Otherwise the matrix
should be out.
It is actually very simple. You can find the command “Show LEDs” in
the “Basic” block. Drag it before the command “otherwise”.
20
Barrier
Sincerely, RoBo
21
Parking garage barrier
For this model as well, I am going to give you a task and, since
you're already an expert programmer, three secondary tasks. You
then have to solve these by creating a control program.
barrier1.hex
When a vehicle drives through the light barrier and interrupts the
light current, the barrier should open after 1 second. It should
remain open for 5 seconds and then close again.
22
Here as well, you will start with the program section
“on start”.
You have
connected
the LED
for your
light barrier
to “Pin13”. This should be
illuminated after you start the
program. Insert the command
and change its properties.
The main part of the program once again starts with the command
“forever”.
Look at the program for the hand dryer once again. In this program,
you query the light barrier and determine the value of the phototran-
sistor. You can use this command sequence for the barrier as well.
The next command is the “if ... Then” command from the “Logic”
block. Drag the command for a query to the “true” rhombus. Change
the value after the “<” to 500.
23
If the value for the light barrier is less than 500, the barrier should
open. To do so, insert “digital write pin ….” twice
for “then”. Change the first command to “P16” and
to “1” and the second command to “P15” and “0”.
When the program is started, the barrier will open or the motor will
start. It should run until the switch on “Pin3” is closed.
To do so, you need the command “while … do” from the “Loops”
block. Drag it under the last command.
Replace the “true” rhombus with a query from the “Logic” block.
Insert the command “digital value of ...” as the first variable. Change
the pin assignment to
“P3”.
24
Test the sub-program. If you interrupt the light barrier, the barrier
opens, activates the switch and stops.
In the task, your job is to ensure that when the light barrier is
interrupted, the barrier opens after 1 second. Add this command to
the right spot and change the wait time to 1 second.
The task also requires that the barrier close again after 5 seconds.
To do so, add the command “pause (ms)” once again. Then the
motor should turn in the other direction until the button on “Pin0” is
pressed.
25
Test the entire program. If you interrupt the light barrier, the barrier
opens, activates the switch and stops. The barrier closes again
after a specified wait time.
barrier2.hex
If the barrier is open when the program starts, it should close first.
Duplicate the program block into the start program from the “forever”
section.
26
Now, the entire program is as follows.
barrier3.hex
Add a program section you can use to start the
system.
27
Now you can test
out the program.
Move the barrier to a
middle position. After
the program has
been downloaded, it
will wait for button
A. Once it is pressed, first the
barrier will close, and then
process the “forever” part of
the program.
First, add the command “led enable” from the LED block to the “Start
block”.
Dock the command using the “while … do” command and change
the value from “false” to “true”.
28
You need the command “show
icon” in two places in the “forever”
program section. Once when the
barrier is open and then once
again when it is closed. Insert the
command and change the LED
display.
29
If something isn't working right ...
... hopefully you can find a solution for your problem in this table.
Finally, I would like to give you an important web address. If you want to learn more
about the micro:bit, you can find further information at
https://microbit.org
Well, it seems we’ve reached the end. I wish you lots of success program-
ming the ft models with makecode.
30
1st edition 2019
Hermann Weininger,
Head teacher and
master electrician
31