Created
January 8, 2018 01:33
-
-
Save lbxa/f9b02d981036048fd9605750fd66d3b2 to your computer and use it in GitHub Desktop.
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
| ''' | |
| Microbit Micropython | Binary Digit LED's | |
| Mini project for NCSS challenge that involved some silly hardcoding | |
| Lucas Barbosa | 8.01.2018 | NCSS Summer School | (C) | |
| ''' | |
| from microbit import * | |
| import random | |
| import music | |
| ON = "1" | |
| OFF = "0" | |
| pins = [pin0, pin6, pin7, pin9] | |
| dec_bin = {0: "0000", 1: "1000", 2: "0100", 3: "1100", 4: "0010", 5: "1010", | |
| 6: "0110", 7: "1110", 8: "0001", 9: "1001", 10: "0101", 11: "1101", | |
| 12: "0011", 13: "1011", 14: "0111", 15: "1111"} | |
| display.off() | |
| while True: | |
| if button_a.was_pressed(): | |
| rand_num = random.randint(0, 15) | |
| print(str(rand_num)) | |
| for dec, binary in dec_bin.items(): | |
| if rand_num == dec: | |
| # turn the binary strings into iterable lists | |
| binary = list(binary) | |
| binary.reverse() | |
| # enumerate to use index for pin output signal | |
| for index, digit in enumerate(binary): | |
| if digit == ON: | |
| pins[index].write_digital(True) | |
| elif digit == OFF: | |
| pins[index].write_digital(False) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment