BBC micro:bit Emoji Bag:You can customise the bag in any way you want, and we have suggested a few additional tasks to encourage students to explore further programming with the BBC microbit
Learn how to:
- Make a simple felt bag from scratch.
- Program your BBC micro:bit to light the built in LED display and two additional LEDs via the output pins.
Level of difficulty:
- 1 x BBC micro:bit.
- 2 x 80 x 40cm pieces of felt.
- 1 x Small piece of felt for the battery pocket.
- 2 x White LEDs.
- Conductive Thread.
- Sewing thread in matching colours.
- 2 x 5mm eyelets.
- 1 x 18cm length hook and loop fastener.
- 1 x Magnetic clasp.
- 3 x Crocodile clips.
- 1 x 2xAAA Battery Cage with JST connector.
- 2 x AAA Batteries..
- 1 x USB to Micro USB lead.
You will also require the following equipment:
- A computer with a USB port and internet access.
- Large eye needle.
- Round nosed pliers.
- Paper template .
Step-by-step guide to making your BBC microbit Emoji Bag
Step 7Go to the BBC microbit website, click “Lets Code”, then look for the Microsoft MakeCode Editor. Let's practice using the block system to build some code. The blocks are organised into categories and the categories are listed in a column down the left-hand side of the screen.
Step 8We need to create a "forever" loop. This is the block that the rest of our code will sit inside. The "forever" loop runs all the blocks inside it starting from the top and working its way to the bottom. Once it gets to the bottom block it starts again at the top and this process will continue forever. Click on the "Basic" category to open it and then drag the "Forever" block into the workspace. (This is the big white area in the middle of the screen.) The forever block is useful as it runs the program again from the beginning once all of the steps have been completed.
Step 9To create the mouth for the face using the LEDs which are located on the BBC microbot we need the "show leds" block. Place this command block in with the "forever" block, they should snap together. Now click in the show leds block to create a smiling mouth. Now we have the mouth for the face programmed we need to program the pins to turn the LEDs on and off for the eyes. We need to use the "digital write" command to turn one of the pins on. Drag the "digital write" block from the "Pins" category into the workspace and put it into the "forever" command. Taking a look at this block we can see that it has a circle on it so that you can input a value of either 1 or 0. You will need to set this to "1" for the first block which will turn the pin on, the second part of the block is setting which pin to turn on and off, leave this set to "P0". Now we need to include a "pause" block so the LEDs stay on for a period of time. The "pause" block is measured in milliseconds, so if we want the LED to remain on for 1 second we need to set the "pause" block value to "1000". Finally, we need to add a second "digital write" block to turn the LED off, we would need to set the number block to "0" and leave the pin set to P0.
Step 10Now, let's try that out! Press the download button and the code should appear in your default downloads folder. If you plug your BBC micro:bit into a USB port it will show up as a storage device. Simply drag and drop the .hex file you just downloaded onto the BBC micro:bit. Now power up your BBC micro:bit with the batteries, then press the "reset" button next to the USB connector you should see the LED turn on.
Step 11So now we have a basic face that lights one of the LEDs. Now let's use both of the LEDs. So copy the "digital write" command block by right-clicking and selecting "duplicate". Change the pin that is being turned on and off to "P2". Try changing the code so that both LEDs come on at the same time, then after 1 second turn one of the LEDs off and very quickly back on to imitate winking. You will need a couple more "digital write" blocks and "pause" blocks to be able to do this. Try it out on your BBC micro:bit to make sure your happy with how it looks.
Step 12Now we have one face working well let's try adding a second face into the code. Create a sad face in the same way we did for the smiling face. Remember to turn the pins on and off for the LEDs, try changing the amount of time that it pauses for to imitate someone blinking quicker when they are upset. Compile the code and try it out on your BBC micro:bit, experiment with the timings until you are happy with the result. We have two different facial expressions, now we want to get the code to repeat a few times before moving onto the next section of code. This requires a "repeat, do" loop, this loop will repeat the code that is contained within the block a set number of times before moving onto the next section of code. Lets put the smiling face code into a "repeat, do" loop and repeat the code 5 times. Now do the same with the sad face code, again get the "repeat, do" loop to repeat 5 times. Compile this code and try it out on your BBC micro:bit, you should see the smiling face 5 times and then the sad face 5 times. As the code is in the forever loop it will keep repeating this sequence.
Further TaskAt the moment our code is automatically triggered and runs continually with no input. Try using features that are built into the BBC micro:bit such as the buttons or the accelerometer to trigger the code. Set your Emoji bag apart from the rest and have a unique way of triggering the code. Hint 1. Use the "set item" variable to name your movement axis, and use the "acceleration" block to set which axis you wanted to monitor. Hint 2. Use an "if, do" loop to set the value for when the code should be triggered. Still need a little more help? Why not have a look at the "Don't Steal my BBC micro:bit Alarm" tutorial. Download the paper template here. Download a pdf version of this page here.
©Kitronik Ltd – You may print this page & link to it, but must not copy the page or part thereof without Kitronik's prior written consent.