Skip to content

Instantly share code, notes, and snippets.

@0atman
Created June 24, 2014 23:48
Show Gist options
  • Save 0atman/a12e22200c55928a0e8d to your computer and use it in GitHub Desktop.
Save 0atman/a12e22200c55928a0e8d to your computer and use it in GitHub Desktop.
A micropython dice roller, output in binary!
import pyb
def set_state():
n = int(pyb.rng() / 2**30 * 6) + 1
[pyb.LED(l).off() for l in range(1,4)]
byte_list = list(str(bin(n))[2:])
byte_list.reverse()
for led, byte in enumerate(byte_list):
if int(byte):
pyb.LED(int(led) + 1).on()
else:
pyb.LED(int(led) + 1).off()
sw = pyb.Switch()
while True:
while not sw():
pass
pyb.delay(300)
set_state()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment