When the micro:bit was first released to schools it came in a choice of 4 colours. On Twitter we talked about making a sorting hat to decide which student would get which colour.
I’ve finally made it! But I’ve just linked it to the 4 houses of Harry Potter 🙂
- Steampunk hat with goggles: http://www.ebay.co.uk/itm/Adults-Steampunk-Victorian-Gothic-Cosplay-Halloween-Fancy-Dress-Accessory-Hat-/352011724341
- Proto-Pic micro:pixel Edge 1×10 WS2812B Board for micro:bit: https://www.proto-pic.co.uk/micropixel-edge-for-microbit.html
- 3mm fibre optic side glow cable, 2 meters: https://www.amazon.co.uk/dp/9875321559/ref=cm_sw_r_tw_dp_x_1nq7zbBP6JZ5H
- Needle and thread
- 3d printed holder to connect the micro:pixel edge to the fibre optical cable. Available to print on thingyverse: https://www.thingiverse.com/thing:2600636
- A micro:bit with a battery pack & batteries
- Print the 3d printed holder
- Connect the micro:bit to the edge
- Connect the 3d printed holder to the edge
- Decide how you want the fibre optic cable to go on the hat. I had one long strip around the rim and individual strips across the top.
- Cut the fibre optic cable in strips.
- Attach the fibre optic cables to the holder
My code randomly shows one of the four colours of the Hogwart’s houses across all the fibre optic cables randomly. Out of the 10 LEDs on the edge I’m only using 6 of them. During the start up sequence I didn’t want the other 4 lights not connected to fibre optic cables to be randomly showing, so I did this in a bit of a complicated way!
- On start, setup the neopixel lights
- Create an array of 6 items with the address of your 6 lights
- Create a function to run through the start sequence 20 times:
- Pick a random number between 0 and 3
- If the number is 0:
- get a random number between 0 and 5
- get the address of the light in that random position
- make it red
- Do the if statement for 1:yellow, 2:blue, 3:green
- Now with the start sequence done – select the house! Pick a random number between 0 and 3
- If the number is 1, set every light to red one at a time. Then flash all lights red 4 times
- If the number is 2, set every light to blue one at a time. Then flash all lights blue 4 times
- If the number is 3, set every light to yellow one at a time. Then flash all lights yellow 4 times
- If the number is 4, set every light to green one at a time. Then flash all lights green 4 times
- The hex code is here: https://makecode.microbit.org/_3oUJWa9oYVed