Introducing The Concept

When I was in the scouts, we used to play wide games where a piece of wool was tied around your arm. This was your “life” and if someone managed to remove it, you were out. The principle was great, however, I am not sure it totally worked in practice.

In 2012, Die Gute Fabrik devoloped a mini game for the Playstation Move controller called Johann Sebastian Joust. Similar idea to the wool, except this time the life was the illuminated ball, and if it was jogged or shaken too much the light would be extinguished. So the aim of the game was to carefully carry your controller, whilst trying to jog others so that they lose.

PlayStation Version of Johann Sebastian Joust

This concept is perfect for the MicroBit which has both LEDs and an accelerometer built in. The first microBit version I discovered was developed by Winkle Ink and played at the Egham Raspberry Jam. Essentially the code is very simple, so lets have a look.

The Basic Version

So basically, when you start, the code sets the LEDs all on, and when shaken, the LED screen is cleared, pause for 10 seconds and then turn it on again. The 10 seconds is enough time to notice that the player is out.

Adjusting Sensitivity

The issue with the basic version is that you cannot adjust the sensitivity. So let’s replace the On Shake command with a Forever Loop and an IF statement.

Using Acceleration (mg) strength totals the acceleration in each direction. By using this command, the programmer can change the sensitivity by altering the boundary by at which the IF statement becomes true and the player has lost.

Giving Fair Warning

But it seems a little unfair that the player crosses the threshold from life to losing with no warning. Adding a ELSE IF statement could change the output for a while if the accelerometer exceeds a lower boundary limit, thus giving fair warning.

Here’s an example, but there is an issue with this, in that the play during the 0.5 second pause can exceed the upper limit without punishment.

Using NeoPixels

So ultimately, to make this into a useable game, it will need to look better and could incorporate more elements to the game play. Using NeoPixels will certainly make the game look better, glowing with more intensity, and different effects can be used. But using colours is where NeoPixels really come into their own. This allows for the creation of team versions of the game.

Setting Up the Game

Breaking down the code, the following blocks set up the neopixels on the MicroBit, initialise the colour and allow you to set a colour for the controller.

Initialise NeoPixels and set start colour

Use Button A to select NeoPixel Colour

The colour is stored as three variables giving the Red, Green and Blue values.

Continuous Checking

To overcome the issue of halting the sensor reading whilst the warning is being given a ‘ShakeSense’ variable is used to store the state of the sensor. The doLose and doCareful functions are called depending on the state of this variable.

Note that the ShakeSense variable (if equal to 1) can still be set to 2.

The Output Functions

The doCareful warning function flashes the lights, but notice that it only resets the ShakeSense variable if still < 2. If in the meantime, the player has shaken too much, the ShakeSense variable remains at 2 and the doLose function will be called.

The doLose function turns the NeoPixels off for 10 seconds and then resets back to the start. This is enough time to show that the player is out.

Casing the Game

This seems best enclosing everything in a translucent plastic container perhaps with a screwtop lid. So having made it work with the prototype board, the next stage it to build the game and play.

Future Development

Using MicroBit Radio seems to be the next element necessary. Perhaps a master controller which resets devices, rather than them coming on after 10 seconds. Using radio would also allow the last two devices to talk to eachother so that in the event that they both go off, it is clear who wins.