BBC micro:bit – Hogwarts Sorting Hat

hogwarts-sorting-hatIn the Harry Potter series of novels written by British author J. K. Rowling, The Sorting Hat is a magical hat at Hogwarts that determines which of the four school Houses each new student belongs most to. These four Houses are Gryffindor, Hufflepuff, Ravenclaw, and Slytherin.

In this challenge we are going to write a program for the BBC micro:bit to act as the sorting hat. Whenever a students from Hogwarts school of Witchcraft and Wizardry will shake the BBC micro:bit, a message will appear telling them which house they belong in.

You will need to use the microbit.org website to get started!

Block Programming


Here is the code to implement the Sorting Hat algorithm:
bbc-microbit-sorting-hat-code-1

Resetting the Sorting Hat


Add the following code to reset the Sorting Hat when either button A or button B is pressed:
bbc-microbit-sorting-hat-code-2

Share Button
Posted in BBC micro:bit, Computer Science Tagged with: ,

Our Latest Book

Follow this blog