Make: micro:bit Harry Potter Sorting Hat

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 ūüôā

 

Equipment

Steps

  1. Print the 3d printed holder 20171022_220637
  2. Connect the micro:bit to the edge 20171022_220614
  3. Connect the 3d printed holder to the edge
  4. 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.
  5. Cut the fibre optic cable in strips.
  6. Attach the fibre optic cables to the holder20171022_220743

20171022_220853Code

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!

    1. On start, setup the neopixel lights
    2. Create an array of 6 items with the address of your 6 lights code1
    3. Create a function to run through the start sequence 20 times:
      1. Pick a random number between 0 and 3
      2. If the number is 0:
        1. get a random number between 0 and 5
        2. get the address of the light in that random position
        3. make it red
      3. Do the if statement for 1:yellow, 2:blue, 3:greencode2
    4. Now with the start sequence done – select the house! Pick a random number between 0 and 3
    5. If the number is 1, set every light to red one at a time. Then flash all lights red 4 times
    6. If the number is 2, set every light to blue one at a time. Then flash all lights blue 4 times
    7. If the number is 3, set every light to yellow one at a time. Then flash all lights yellow 4 times
    8. If the number is 4, set every light to green one at a time. Then flash all lights green 4 timescode3
    9. The hex code is here: https://makecode.microbit.org/_3oUJWa9oYVed

 

Advertisements

One thought on “Make: micro:bit Harry Potter Sorting Hat

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s