Microbit using the accelerometer in the block editor

In this next example using the block editor we will use the accelerometer that is on the Micro:bit board  to detect when the micro:bit is being shaken, if it is shaken we will display a number between 1 and 6 on the LED’s, similar to a dice.

The pick random block generates numbers in a range starting at 0. If we generate the numbers 0-5 we then need to add 1,and then we get a die roll from 1 to 6.

You need to create the following

microbit-shake-die-1

Compile, copy the hex file into your Micro:bit and test by shaking your Micro:bit and looking at the LEDs

Of course that’s not really a proper die, so what you really want to do is depending what number die is equal to display an image that represents that on the LEDs, here is part of an example. I couldn’t fit all of the numbers in but should get the general idea from the image below, a bit harder to create but the effect is much better

microbit-die-2

Leave a Comment

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views :