What could be better than a little bit of magic as an engaging way to introduce the micro:bit to micro:bit communication to your pupils?
Hand out a set of micro:bits to the class and make sure they are powered up (either plug in the battery pack or connect them to a computer via the download cable).
Conceal a micro:bit in your pocket.
Start talking to the class about the micro:bit tell them about things that you know will make the micro:bit happy and things that make it sad. As you do so the pupils micro:bits will keep changing their expressions from happy to sad and back to happy to match your story.
This is magic!
Your pupils will be amazed!
This is how the trick works.
The trick makes use of an excellent feature built into the micro:bit - radio communication.
As you tell the class a 'sad' thing, unseen you press button B on your concealed micro:bit and as you tell them a happy thing, you press button A.
But first you must program all of the micro:bits.
The teacher's micro:bit has the transmitter code and the pupil's micro:bits all have the receiver code.
3Transmitter code Receiver code
This project exemplifies the versitility of the micro:bit for STE(A)M. A pupil built a farground ride out of cardboard, recycled wood and a couple of plastic pulley wheels.
The pupil also manged to find four toy horses to decorate the ride.
List of other components:
200:1 ratio 6 volt motor
micro:bit
motor control board
6 volt power pack, 6 volt buzzer, LED and protecting resistor
push button switch
This project is to create an automated fairground ride. The style of ride is built onto a rotating platform which is computer controlled. The platform can rotate in a horizontal or vertical direction and can rotate both forwards and backwards.
In this example, the learner has created a carousel or merry-go-round.
The ride will be controlled using a micro:bit. Using motors with a micro:bit introduces a problem.
The micro:bit is limited for motor control, because the 3 volt output is insufficient to drive most motors. For motor control projects the 6 volt 200:1 geared motors are most commonly used. This means that a 6 volt battery pack has to be included as part of the circuit to control the motor in the fairground ride.
This introduce the important control concept of using a low voltage control circuit to switch on an higher voltage activator circuit such as a motor or servo.
This is managed using a component known as a relay (shown below).
The low voltage circuit (3 volts), via the relay, switches on the high voltage lamp circuit (6 volts)
For use with the micro:bit this needs to be a 3V relay.
This is a possible fairground ride algorithm for fairground ride illustrated above:
If button A is pressed, display an O
Turn the buzzer on (motor 2) for 1 second
Turn the motor on forwards (motor 1) for 3
Turn on the LED (Pin 13)
Turn the motor on reverse (motor 1) for 3 seconds
Turn the motor off
Turn the buzzer on (motor 2) for 1 second
Turn the LED off
The script below does NOT match the algorithm above.
Edit to debug this script so that it does match the algorithm.
When creating code for robotics project you will use a coding language such as Scratch, MakeCode or Python. One thing all of these languages have in common is that a special program called a compiler or interpreter translates your code into machine code—which is in binary so that it can be processed by the computers CPU.
The word binary dates back to Roman times and means two of something.
We use the prefix bi in many ways today.
A bicycle has two wheels, binoculars have two lenses, and we are bipedal as we stand on two legs.
The bi in binary refers to system of representing information that uses just two digits, 0 and 1.
Everything a computer does is processed using binary code, from text,
to numbers...
to pictures...
to music...
to video games etc.
Let's start by looking at how we can represent any number using binary.
You're use to reading a number like this. The digits represent how many ones, tens, hundreds there are in the number.
The system is called denary.
Notice how as you move from right to left, the digit's value is multiplied by 10. This is because the denary counting system using Base 10.
This is an example of the binary number 01011101. It's denary equivalent is 93.
Just like denary, the digits of the binary number have a value based on where they are in the number.
Unlike denary where the digits have values like 3, 6, or 8, binary digits can only be zero or one.
Starting from the left the value of each position is 1, then 2, then 4, then 8, then 16, then 32, then 64, and finally 128.
When reading a binary number, you check which columns have a one in them, and then add up all the values those places represent.
Notice how as you move from right to left, the digit's value is multiplied by 2. This is because the binary counting system using Base 2.
At their most basic level, computers are made up of switches (more officially called transiters).
Just light a regular light switch in your home, the switch can either be on or off.
In computing we can represent the off state with the number zero and we can represent the on state using the number one.
As everything in a computer is made up of switches the can only process data that is represent in binary states.
Watch the following video to learn more!
Logo, sometimes known as turtle graphics, is a computer programming language.
There are many different programming languages such as, Scratch, Python, Basic, Javascript, Logo etc. etc..
Logo is normally used to control a virtual screen 'turtle'.
However, companies such as Valient have produced physical, robot turtles.
Watch the video below showing a turtle robot controlled by some Logo code to make it draw using its built in pen.
The turtle leaves a trace when it moves, so Logo is great for drawing geometrical shapes and patterns (see below).
In fact with a bit of practice you can draw anything with Logo.
There is no need to register as you do not have to save your code.
The on screen robot turtle will simulate your code as it runs (see the Logo interpreter app below)
The text in bold below is code you can use to experiment with Logo programming, then click Run.
Try the commands below in sequence (to save typing, you can copy the command (bold text) and paste it into the editor to test it.
Always leave a space between the command and the number e.g. fd 100:
Test each of these commands, one at a time, to find out what they do:
pd (puts the pen down onto the paper so that Logo will draw as it moves
setpencolor 4 (this is the code to change Logo's pen to red)
fd 100 (move forward 100 steps)
rt 90 (turn right by 90°)
setpencolor 1
fd 100
rt 90
setpencolor 2
fd 100
rt 90
setpencolor 3
fd 100
rt 90
To clear the screen of unwanted drawings and reset the turtle enter cs and Run.
Logo is excellent at drawing geometric shapes or polygons such as triangles and squares.
In Lesson 1 you used 8 lines of code to draw a square.
fd 100
rt 90
fd 100
rt 90
fd 100
rt 90
fd 100
rt 90
This is very inefficient, and inefficient code wastes time and memory.
In fact you can draw a square with just one line of code if you use a repeat statement.
In computing this is known as looping or iteration.
Study the flowchart algorithm below to see how this works.
Flowchart algorithm
The algorithm can be coded in Logo as shown below, test the code to see what the turtle draws:
repeat 4 [fd 100 rt 90]
Once you have a way of doing something you can adapt it to do similar but slightly different tasks. This is known as generalisation.
Look at the two scripts below and predict what they will draw.
What shape will repeat 3 [fd 100 rt 120] draw?
What shape will repeat 5 [fd 100 rt 72] draw?
Write your predictions on your progress record.
Test the scripts in Logo to see if you were right.
To find the angle you divide 360 by the number of sides in your shape.
Triangle it is 360 ÷ 3 = 120 degrees
Square it is 360 ÷ 4 = 90 degrees
Pentagon it is 360 ÷ 5 = 72 degrees
Hexagon it is 360 ÷ 6 = degrees
Octagon it is 360 ÷ 8 = degrees
From now on you MUST use a repeat statement.
Now it is your turn - use the diagrams above to help you to predict the angles to create a script to draw:
Draw a hexagon (paste your script onto your Logo progress record).
Draw an octagon (paste your script onto your Logo progress record).
If you add up all the angles they will always give the answer 360.
We can use generalisation to work out how to draw any regular polygon.
The flowchart below is an abstracted algorithm that we can generalise for drawing any polygon.
Abstraction just means remove the detail, so instead of the actual number of sides we have used the letter n as a variable to stand in for the number of sides in the polygon.
Abstracted flow chart algorithm
The angle of turn will always be 360 divided by the number of sides in the polygon:
triangle = 360 /3 = 120 degrees
square = 360 /4 = 90 degrees
hexagon = 360 /6 = 60 degrees
octagon = 360 /8 = 45 degrees
etc.
This is a good example of generalisation, we have taken our code and used it to solve many different problems.
Programming languages usually let you build blocks of code that do a particular thing - such as drawing a square.
These are known as functions (in Logo they are also known as procedures, but they are the same thing).
Good programmers write program code that is structured into functions.
Writing programs using functions has a number of advantages:
They give a clear structure to the program.
The program is broken down into simpler problems to solve.
It is possible to use functions more than once in a program.
Writing a program using functions makes it easier to test and debug (correct errors).
Functions are shorter and easier to understand.
Functions can be saved and used on another occasion.
In the Logo Interpreter, click on the arrow in the text box at the bottom of the screen to expand it.
In the text box, type to followed by the name of your function, square.
Now type the script to draw a square using the repeat command.
Finally type the word end, this tells the turtle when the function has finished.
Your function should look like this:
to square
repeat 4 [fd 100 rt 90]
end
To make the turtle animate your function, you must call it by typing its name in the text box.
Type square, and click Run.
Your function will appear in the Your program box above the Enter new logo commands box.
Double click on the code to edit your functions.
When you test a function it might not do precisely what you want.
Double click on your function in the Your program window (in the top right corner)
You will now be able to edit your function in the New Logo commands window.
Click the blue arrow to store your new function.
Try it now, make your square function draw a smaller square by changing fd 100 to fd 50.
Programmers use something called arguments to pass data to their functions.
For example, if you have a procedure that will draw a square, you can use an argument to change the size of the square it draws.
In the examples, the data passed to the box procedure was stored in a variable named :size. This variable will hold what ever data is passed to the function when it was called.
Create the function shown below:
to box :size
repeat 4 [fd :size rt 90]
end
Now call your new function three times as shown in a), b) and c) below:
a) box 50
b) box 100
c) box 150
You can use arguments to change the pen colour for your functions.
Create the procedure below
to colchange :num
setpencolor :num
fd 25
repeat 18 [fd 50 rt 77]
end
Call the function several times, using a different number each time.
For example, try calling ....
colchange 6
Now try calling ....
colchange 3
Keep on calling colchange followed by a different number to produce and multi coloured pattern.
You can create a function to draw ANY regular polygon (see the code below).
to anypoly :n
repeat :n [fd 50 rt 360/:n]
end
Call the function several times, using a different number each time.
Find out how many sides an icosagon has and program Logo to draw one.
How many sides did your icosagon have?