22 lines
539 B
Python
22 lines
539 B
Python
from microbit import *
|
|
import random
|
|
|
|
# Define dice faces
|
|
dice_faces = {
|
|
1: "00000:00000:00900:00000:00000",
|
|
2: "90000:00000:00000:00000:00009",
|
|
3: "90000:00000:00900:00000:00009",
|
|
4: "90009:00000:00000:00000:90009",
|
|
5: "90009:00000:00900:00000:90009",
|
|
6: "90009:00000:90009:00000:90009"
|
|
}
|
|
|
|
def show_dice(number):
|
|
display.show(Image(dice_faces[number]))
|
|
|
|
while True:
|
|
if accelerometer.was_gesture('shake'):
|
|
num = random.randint(1, 6)
|
|
show_dice(num)
|
|
sleep(1000)
|
|
display.clear() |