Hello world! Welcome back to the microbit series. I am Alina
and today we want to make a tame lion.
In the previous video, we had used single selection control to
control the servo motor if microbit is shaken.
This time we will use a self-made sensor to control
the servo motor using a loop selection
structure. Prepare all the project materials this time:
colour paper and cardbaord, aluminium foil,
connecting wires, micro servo motor 3V,
5 crocodile clips, power supply or battery and
microbit board.
Cut out the lion shape in 2 copies. Separate the lion's head
from its body. Wrap one of the tail with the
aluminium foil.
Stick the aluminium foil to the back of another lion's tail
like this.
Clip one of the tail to GND and another one to
P0.
Connect the wires to the servo motor.
Orange wire to white wire, red wire to red wire and
brown wire to the black wire. Clip
the white colour wire to pin 1,
black color wire to GND
and red wire to 3V.
Insert the blade to servo motor. Stick the servo
motor to the lion's head.
We want to program microbit to move the lion's head according to
the number its tail is pressed.
For example, when we press the lion's tail for
5 times, we want the lion's head to move 5 times
when the button A is pressed. We start off
with the programming of touch sensor first.
Construct a new variable and name it as "tail".
At "on start", insert the block "set tail
to 0".
Every time when the tail, which is pin P0, is pressed,
we increase the value of "tail". Use the forever block.
Put in the block "If-then".
Put in the condition for "pin P0 is pressed".
If P0 is pressed, put in the block to add the value of
tail by 1".
"change tail by 1". Use the pause block
and set the timing to 100 milliseconds.
Show value of the tail by using the blocks "show number" and the variable "tail"
"show number"
"variable"
"tail"
Now we want to move the lion's head as many times as its tail is pressed.
We use "on button A pressed".
Use the block "Repeat" to make sure the lion's head
moves according to the times its tail P0
is pressed.
Use the block "set servo P1
angle to 60 degree" to move its head.
Use block pause for 500 milliseconds.
Then block "set servo P1 angle
to 120 degree".
Block pause 500 milliseconds.
Connect microbit to the computer using a USB cable.
Press download on the software and save the programming file
into the microbit. Remove the USB cable from the microbit.
Connect the power supply or battery to microbit.
Tidy up your project.
Switch on the power supply and observe what will happen when
the lion's tail is pressed.
The number of times its tail is pressed will be displayed
on the microbit board. Press button A now.
The lion's head will move according to the value
shown on the microbit board.
One, two,
three.
Tidy up your project and try to arrange the wires and the microbit board
so that they are not seen from the front. Project tame lion is done!
As for the challenge, program the microbit to reset
the count when the button B is pressed. Happy trying!