Created
June 24, 2014 23:48
-
-
Save 0atman/a12e22200c55928a0e8d to your computer and use it in GitHub Desktop.
A micropython dice roller, output in binary!
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 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