microbit python tutorial: shake ‘n’ burn fire simulator

Extend it with code
How can you improve it?

We’ve used the micro:bit’s built-in accelerometer to check if it’s been shaken, but it can do far more than that too. Have a look at the python docs for the accelerometer and see if you can do any of the following challenges:

  1. Make it so that the flames always rise upwards, even if the micro:bit is held on its side or upside down.

    Hint: You can detect the “face up”, “face down”, “right” or “left” gestures in the same way that we’ve already detected the “shake” gesture. You just need to work out how to shift the image in the right direction and set the random LEDs in the right place for each.

  2. Make it into a little game so that you get a point for every second the fire is alive, but if it dies out completely the game is over.

    Hint: You can find out how long the program has been running using the running_time()  function. More info here.

  3. Make it so that the fire doesn’t die out by itself but so that it gets hotter if you press button A and cooler if you press button B.

    Hint: You’ll need to change the value of the intensity variable: increase it to make the fire hotter and decrease it to make the fire cooler

Leave a Reply

Your e-mail address will not be published. Required fields are marked *