Created
October 12, 2018 20:44
-
-
Save hannorein/4f6be93a19ac0ecba35fbffaa189df34 to your computer and use it in GitHub Desktop.
This file contains 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 time | |
lowpins = [] | |
for i in [0,16,5,4]: | |
lowpins.append(machine.Pin(i, machine.Pin.OUT)) | |
highpins = [] | |
for i in [14,12,13,15]: | |
highpins.append(machine.Pin(i, machine.Pin.IN)) | |
led = machine.Pin(2, machine.Pin.OUT) | |
for i in range(4): | |
led.value(0) | |
time.sleep(0.125) | |
led.value(1) | |
time.sleep(0.125) | |
matrix = [[1,2,3,"A"],[4,5,6,"B"],[7,8,9,"C"],["*",0,"#","D"]] | |
def getkey(): | |
for i in range(4): | |
for j in range(4): | |
lpin = lowpins[j] | |
lpin.value(1) | |
time.sleep(0.00125) | |
if highpins[i].value()==1: | |
return matrix[i][j] | |
time.sleep(0.00125) | |
lpin.value(0) | |
return None | |
value = 0 | |
while 1: | |
key = getkey() | |
if key is not None: | |
if key=="D": | |
a = 0 | |
b = 1 | |
for i in range(value): | |
t = a + b | |
a = b | |
b = t | |
print("fib(",value,"): ",a) | |
for k in range(a): | |
led.value(0) | |
time.sleep(0.125) | |
led.value(1) | |
time.sleep(0.125) | |
value = 0 | |
else: | |
value = value*10+key | |
time.sleep(0.25) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment