Created
July 31, 2017 00:53
-
-
Save mbparks/ca7acc45e8aee34883b78b7faec58233 to your computer and use it in GitHub Desktop.
Micropython code for Microbit, simulate a 6-sided die (Button A) and a 20-sided die (Button B)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from microbit import * | |
sixSides = [ | |
"1", | |
"2", | |
"3", | |
"4", | |
"5", | |
"6", | |
] | |
twentySides = [ | |
"1", | |
"2", | |
"3", | |
"4", | |
"5", | |
"6", | |
"7", | |
"8", | |
"9", | |
"10", | |
"11", | |
"12", | |
"13", | |
"14", | |
"15", | |
"16", | |
"17", | |
"18", | |
"19", | |
"20", | |
] | |
display.scroll("D&D") | |
while True: | |
display.show(Image.GHOST) | |
sleep(1000) | |
if button_a.is_pressed(): | |
currentSide = random.choice(sixSides) | |
display.scroll(currentSide) | |
sleep(1000) | |
display.scroll(currentSide) | |
sleep(1000) | |
if button_b.is_pressed(): | |
currentSide = random.choice(twentySides) | |
display.scroll(currentSide) | |
sleep(1000) | |
display.scroll(currentSide) | |
sleep(1000) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment