from machine import Pin
from time import sleep
T1 = Pin(0, Pin.IN)
T2 = Pin(1, Pin.IN)
T3 = Pin(2, Pin.IN)
T4 = Pin(3, Pin.IN)
LED0 = Pin(4, Pin.OUT)
LED1 = Pin(5, Pin.OUT)
LED2 = Pin(6, Pin.OUT)
LED3 = Pin(7, Pin.OUT)
LED4 = Pin(8, Pin.OUT)
LED5 = Pin(9, Pin.OUT)
LED6 = Pin(10, Pin.OUT)
LED7 = Pin(11, Pin.OUT)
LED = [LED0, LED1, LED2, LED3, LED4, LED5, LED6, LED7]
def addZeros(string, length):
while len(string) < length:
string = "0" + string
return string
def buttonValues(a, b, c, d):
return T1.value() == a and T2.value() == b and T3.value() == c and T4.value() == d
counter = 0
while True:
if buttonValues(1, 0, 0, 0) and counter < 255:
counter = counter + 1
elif buttonValues(0, 1, 0, 0) and counter > 0:
counter = counter - 1
elif buttonValues(0, 0, 1, 0):
counter = 0
elif buttonValues(0, 0, 0, 1):
counter = 255
binary = bin(counter)
bits = addZeros(binary[2:], 8)
for i in range(0, 8):
LED[i].value(int(bits[i]))
# kako bi se osiguralo okidanje samo na uzlaznu ivicu sata
# tj. sprijecile visestruke akcije u logickoj jedinici
while T1.value() or T2.value() or T3.value() or T4.value():
pass
sleep(0.2)