#MonthOfMaking – Day 2

#MonthOfMaking – Day 2

micromag

March 2, 2019

March is all about MAKING!!

I have decided to take on the challenge of making a 5-minute micro:bit make every day throughout March.

Day02 – Random Number Generator

Today I decided to make a random number generator.

The random number generator will generate a number between 1 and 5 and dsiplay it on the micro:bit. Lets get coding!

Python Code


from microbit import *
import random
display.scroll("Shake Me")
while True:
if accelerometer.was_gesture('shake'):
    shake = random.randint(1, 5)
    if shake == 1:
        display.show(1)
    if shake == 2:
        display.show(2)
    if shake == 3:
        display.show(3)
    if shake == 4:
        display.show(4)
    if shake == 5:
        display.show(5)

EduBlocks Code

EduBlocks code

MakeCode Code

MakeCode code

Demo

Alternate Code

Python Code


from microbit import *
import random
display.scroll("Shake Me")
while True:
if accelerometer.was_gesture('shake'):
    shake = random.randint(1, 5)
    display.show(shake)

EduBlocks Code

MakeCode Code

Final Words

Come back Tomorrow for another fun 5 minute micro:bit make

Kerry Kidd
Editor in Chief