import time
import machine
from machine import Pin
tasteri = [ Pin(i, Pin.IN) for i in range(4) ]
dig_pins = [ Pin(d, Pin.OUT) for d in range(4, 8) ]
seg_pins = [ Pin(s, Pin.OUT) for s in range(8, 15) ]
cifre = {
0: 0b1000000,
1: 0b1111001,
2: 0b0100100,
3: 0b0110000,
4: 0b0011001,
5: 0b0010010,
6: 0b0000010,
7: 0b1111000,
8: 0b0000000,
9: 0b0010000,
10: 0b1111111
}
def prikazi_cifru(cifra):
binar = cifre[cifra]
for i in range(7):
seg_pins[i].value(binar & 1)
binar = binar >> 1
def izaberi_poziciju(poz):
for i in range(4):
dig_pins[i].value(0)
dig_pins[poz].value(1)
def prikazi_brojac(brojac):
d = 1000
for i in range(4):
prikazi_cifru(10)
izaberi_poziciju(i)
prikazi_cifru((brojac // d) % 10)
d /= 10
count = 0
stanja_tastera = [ taster.value() for taster in tasteri ]
auto = False
while (True):
if auto:
if it == 0:
count += 1
it = 9
it -= 1
if (tasteri[0].value() and not stanja_tastera[0]):
count = (count + 1) % 256
elif (tasteri[1].value() and not stanja_tastera[1]):
count = (count - 1) % 256
elif (tasteri[2].value() and not stanja_tastera[2]):
count = 0
elif (tasteri[3].value() and not stanja_tastera[3]):
auto = not auto
it = 0
for i in range(4):
stanja_tastera[i] = tasteri[i].value()
prikazi_brojac(count)