Here’s a simple micro:bit project to help you practice converting between binary and decimal (denary / base 10) numbers up to 31.
Binary place values
16
8
4
2
1
1
0
1
0
1
In this example, 10101 in binary in decimal is 16 + 4 + 1 = 21.
Press button A and your micro:bit shows a random decimal number between 1 and 31.
Press button B and it shows the binary equivalent, represented on the top row of LEDs as lit for 1 and dark for 0.
You can use this to challenge yourself – press B to see the dots and work out the decimal equivalent, press A to see if you’re right. Or press A to get the decimal number, work out what the 0s and 1s should be, and press B to see if you got it correct.
Shake the micro:bit to generate a new random number.
It uses a version of the ‘divide by 2′ algorithm for converting base 10 (decimal) numbers to binary:
1 – divide number by 2
2 – store the remainder in an array
3 – repeat steps 1 and 2 until number = 0
4 – print the array in reverse order
I found teaching logic gates one of the trickier parts of the secondary Computer Science curriculum: they’re abstract, dry… not much fun. Year 9 in a girls’ school. Tough crowd. To counter this, I tried to make them a bit more tangible. I raided the Physics (or was it DT?) department for these rather splendid, and tragically no longer manufactured, modular lightbulbs and switches to make AND and OR gates we could wire up in class:
You can make a NOT gate with a relay, but beyond that it gets tricker. There are modular logic gates you can buy, but they’re very expensive, so I switched to using the marvellous logic.ly website to get my pupils to wire logic gates together to make half adders and full adders – the building blocks of everything from calculators to phones to computers. With my year 9s, logic gates made more sense when we could use them to add up:
Here you can see two switches used as inputs to the half adder. The lightbulbs show the output. With both switches off (0 + 0) you get no lights: 00 in binary. With either input switch on (1 + 0 or 0 + 1) you get 01 binary out. Turn both switches on, however, 1 + 1 = 10, which in binary is true as 10 is how you write the number 2 in binary.
More recently I made some simple MakeCode programs to turn micro:bits into physical logic gates so you can make a half adder. You’ll need 6 micro:bits and a heap of crocodile clip or banana plug leads for this, plus battery packs – though you could get pairs of pupils to program each element, or write the programs themselves from scratch.
There are 4 kinds of device:
input switches which send a digital output 0 or 1. Press button A for 0, button B for 1, which sends a digital 1 from the pin 0 output.
AND gates send a digital 1 output on pin 2 if input pins 0 and 1 are high,
XOR gates send an output on pin 2 if either inputs on pins 0 or 1 are high, but not both.
output displays show 0 or 1 depending on whether they receive a digital input on pin 0.
You do also have to join all the GND pins together to complete the electrical circuit, certainly if you’re using batteries – you can daisy chain them together. I didn’t show that on the diagram above for clarity. (If you’re powering them all off the same USB supply you may get away without daisy-chaining the GND pins together for reasons not unadjacent to witchcraft).
Here’s the code for the input switch:
The XOR gate:
The AND gate:
The output display:
…and here’s a video showing them in use, albeit messily on my desk:
And yes, the irony of using a micro:bit – which contains thousands and thousands of logic gates – to emulate a single logic gate is not lost on me. But you may have a class set of micro:bits that could help make logic gates more tangible. You could make other logic gates to get a full set. Could you build a full adder? A bigger calculator? Something else?
I’ve made a few simple projects to turn a BBC micro:bit into (sort of) musical instruments.
First, I made a simple arpeggiator. The micro:bit is, of course, only capable of playing 1 note at a time, but take 3 notes from a chord and break them apart and you get something that sounds… like music:
Next I tried to make a theremin-type instrument, controlling the pitch of the tone being played by changing the physical pitch (tilt) of the micro:bit:
Here’s the code that makes it work:
And finally, I used the micro:bit’s magnetometer: the stronger the magnetic field detected, the higher the pitch of the sound:
You can’t really use the magnetometer in the simulator, but here’s the code for the project – only the ‘forever’ block is important, the buttons were used when testing it.
If you make some noise with your micro:bit, I’d like to know about it!
Now I’m having a go at making my own gin-like drink. No idea if this is going to work, but the plan is this: I filled a small jar with vodka and added the ingredients listed below. It already smells like gin! I’m hoping that the longer I leave it, the more intense the flavours will be and hence the more I will be able to dilute the resulting ‘tea’ with plain vodka to make it go further.
Here’s what’s in the jar:
Handful of juniper berries – this is essential!
3 petals of star anise
about 10 coriander seeds
a sage leaf from the garden
some cucumber peel
tiny amount of dried thyme
a cardamom pod and its seeds, crushed
a sliver of nutmeg
a few rosemary leaves
a kaffir lime leaf
a few fennel seeds
small amount of cinnamon
some lemon peel, thinly-sliced
fresh ginger, small amount, thinly-sliced
I’ll post an update in a week or two when I’ll see if it’s ready for sipping!
I love vermouth. I like a vodka martini, a regular one and more than both of those things I love the smell of dry white vermouth hitting the risotto pan and evaporating straight into my nostrils.
In recent years the price of Noilly Prat has forced me into the arms of supermarket own-brand vermouths, which are generally fine, but the other day I got wondering how hard it could be to make your own. I had a vague idea vermouth was made by putting wine in a barrel with herbs and spices and leaving it to bake in the Mediterranean sun for months. Not having access to the sun, I did some quick research and found a heap of recipes for making your own vermouth. I even discovered that vermouth is actually named after one of its ingredients, wormwood, the same bitter herb used to make absinthe. And absinthe, as we know, makes the heart grow fonder.
There seem to be two main methods for rolling your own vermouth: quick and hot and slow and cold. The former involves heating the wine with your botanicals (herbs and spices) and then mixing the cooled liquid with some form of caramel and possibly a stronger alcohol. The latter method, slow and cold, involves steeping your botanicals for up to two weeks in a spirit (vodka or eau de vie) and then mixing with the wine. I’m going for slow and cold because that’s the kind of mood I’m in.
I don’t have and am not about to acquire any wormwood – I’ll add a dash of absinthe if I think it’s not bitter enough – but I did have a few herbs & spices lying around. I half-filled a jam jar with vodka and added:
1 clove
a tiny sliver of fresh ginger
3 petals of star anise
a sliver of lemon peel
a few coriander seeds
a fresh sage leaf from my garden
a small amount of dried thyme
a few juniper berries (who knew gin was available in fruit form?)
the seeds of 1 cardamom pod
about 1cm of a vanilla pod
about a dozen rosemary leaves
a sliver of nutmeg
The amazing thing is that after just an hour this already smells like vermouth!
I’ll report back in 2 weeks when I mix this up with some dry white wine and possibly that absinthe.