Skip to content

Instantly share code, notes, and snippets.

@mbparks
Created July 31, 2017 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbparks/ca7acc45e8aee34883b78b7faec58233 to your computer and use it in GitHub Desktop.
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)
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