#diamond2016 - richardg - 25.04.2022
# lb402md
from machine import Pin
import utime
from machine import RTC
# assigns segments of pl402md to pico pins value 1 (high is led off)
display_dict = {
'e1':Pin(1, Pin.OUT, pull=None, value=1),
'd1':Pin(2, Pin.OUT, pull=None, value=1),
'c1':Pin(3, Pin.OUT, pull=None, value=1),
'dp1':Pin(4, Pin.OUT, pull=None, value=1),
'e2':Pin(5, Pin.OUT, pull=None, value=1),
'd2':Pin(6, Pin.OUT, pull=None, value=1),
'g2':Pin(7, Pin.OUT, pull=None, value=1),
'c2':Pin(8, Pin.OUT, pull=None, value=1),
'dp2':Pin(9, Pin.OUT, pull=None, value=1),
'b2':Pin(10, Pin.OUT, pull=None, value=1),
'a2':Pin(11, Pin.OUT, pull=None, value=1),
'f2':Pin(12, Pin.OUT, pull=None, value=1),
'b1':Pin(13, Pin.OUT, pull=None, value=1),
'a1':Pin(14, Pin.OUT, pull=None, value=1),
'g1':Pin(15, Pin.OUT, pull=None, value=1),
'f1':Pin(16, Pin.OUT, pull=None, value=1)
}
all_dig1 = {'e1','d1','c1','b1','a1','g1','f1'}
all_dig2 = {'e2','d2','g2','c2','b2','a2','f2'}
zero_dig1 = {'e1','d1','c1','b1','a1','f1'}
zero_dig2 = {'e2','d2','c2','b2','a2','f2'}
digits_dict = {
('L',0): zero_dig1,
('L',1): {'b1', 'c1'},
('L',2): all_dig1 - {'f1', 'c1'},
('L',3): all_dig1 - {'f1', 'e1'},
('L',4): all_dig1 - {'a1', 'd1', 'e1'},
('L',5): all_dig1 - {'b1', 'e1'},
('L',6): all_dig1 - {'a1', 'b1'},
('L',7): {'a1', 'b1', 'c1'},
('L',8): all_dig1,
('L',9): all_dig1 - {'e1'},
('L','p'): {'dp1'},
('R',0): zero_dig2,
('R',1): {'b2', 'c2'},
('R',2): all_dig2 - {'f2', 'c2'},
('R',3): all_dig2 - {'f2', 'e2'},
('R',4): all_dig2 - {'a2', 'd2', 'e2'},
('R',5): all_dig2 - {'b2', 'e2'},
('R',6): all_dig2 - {'a2', 'b2'},
('R',7): {'a2', 'b2', 'c2'},
('R',8): all_dig2,
('R',9): all_dig2 - {'e2'},
('R','p'): {'dp2'}
}
def go(cmd):
if cmd == "L":
for k in display_dict.keys():
if (k[-1] == '1'):
led = display_dict[k]
print ("led: " + k)
led.toggle()
utime.sleep(1.0)
led.toggle()
elif cmd == "R":
for k in display_dict.keys():
if (k[-1] == '2'):
led = display_dict[k]
print ("led: " + k)
led.toggle()
utime.sleep(1.0)
led.toggle()
else:
led = display_dict[cmd]
print ("led: " + cmd)
led.toggle()
utime.sleep(2.0)
led.toggle()
def reset (digit):
if digit == 'L':
for k in all_dig1:
led = display_dict[k]
led.value(1)
led = display_dict['dp1']
led.value(1)
elif digit == 'R':
for k in all_dig2:
led = display_dict[k]
led.value(1) #high is led off
led = display_dict['dp2']
led.value(1)
else:
reset('L')
reset('R')
def display():
for k in digits_dict.keys():
set = digits_dict[k]
reset()
for segment in set:
print (segment)
led = display_dict[segment]
led.value(0) #low is led on
utime.sleep(1.0)
def show(digit, number):
set = digits_dict[(digit, number)]
reset(digit)
for segment in set:
print (segment)
led = display_dict[segment]
led.value(0) #low is led on
def show2Digits(number):
if (number > 99):
return
reset(0)
l = number // 10
show('L',l)
r = (number - l * 10) % 10
show('R',r)
def hhmm ():
rtc = machine.RTC()
# (year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])
rtc.datetime()
print(rtc.datetime()[4])
show2Digits(rtc.datetime()[4])
utime.sleep (2.0)
show2Digits(rtc.datetime()[5])
utime.sleep (2.0)
show2Digits(rtc.datetime()[6])
utime.sleep (2.0)
while True:
hhmm()
Comments