Microbit coin flipper

Microbit coin flipper

Running up to a new Maker's week at the end of July, I was getting a bit bored with the tamagotchi example that uses the accelerometer gestures (shake) to wake up a virtual pet. When the pet is asleep it shows a sleepy icon and you can shake it awake for a few seconds, when it shows a happy face.

I came up with a similar idea to simulate a coin toss using shaking and showing one of two images based on heads or tails.


# random coin flipper
from microbit import *
import random

while True:

    display.show(Image.NO)
    
    if accelerometer.was_gesture('shake'):
        coin = random.choice(['heads', 'tails'])
        
        if coin == 'heads':
            display.show(Image.SKULL)
        else:
            display.show(Image.SQUARE)