# Authored by Jonathan Scott James the great On WOKWI
# 74hc595 pin12=latch.. pin14=data pin11=clk
# gpio0=latch gpio2=clk gpio3=data_out gpio4=data_in
machine.Pin(26, machine.Pin.IN) #ADC
machine.Pin(27, machine.Pin.IN, machine.Pin.PULL_DOWN) #key 2 bottom key
machine.Pin(28, machine.Pin.IN, machine.Pin.PULL_DOWN) #key 1 top key
machine.Pin(0, machine.Pin.OUT, machine.Pin.PULL_DOWN) #latch pin
ttt=1;t=3600*24*366+28;t=3600*24*22-9 # python sets the precision level when you first assign the number according to what will fit in the value you assign it to.
def tickjsj():
    global t
    t=t+1
machine.Timer().init(period=1000, callback=lambda t:tickjsj())
# nn=3600*24*366*28;m=nn;d=nn;s=nn;nn=1;b2b=0;d=12;k=0;b=0;kk=0;bb=0;sevenSeg="1111110011000011011011111001011001110110111011111111000011111111111011";
tt=" "
eightbitsevensegreversed="00111111000001100101101101001111011001100110110101111101000001110111111101101111"
ssebr=eightbitsevensegreversed
k=0;b=0;k2=0;b2=0
puter=bytearray(1)
while 1:
  k=machine.Pin(28).value()
  if (k>b):
    k1=k1+1-4*(k1>3)
  b=k
  k2=machine.Pin(27).value()
  if (k2>b2):
    k1=k1+1-4*(k1>3)
  b2=k2
  rvdc=machine.ADC(26).read_u16()
  if ttt==t:
    print(end="")
    #machine.lightsleep(100)
  if ttt!=t:
    ttt=t
    s=str(int((t/60-t//60)*60));m=str(int((t/3600-t//3600)*60));h=str(int((t/86400-t//86400)*24));d=str(t//86400);w=str((t//86400*7))    # Extrapolate seconds hours minutes and days from raw uptime seconds
    tt=("00"+d)[-2:]+("00"+h)[-2:]+("00"+m)[-2:]+("00"+s)[-2:]+"77" # compile the output buffer 
    for nn in range(8):
      n=int(tt[nn])
      machine.SPI(0,baudrate=1024,sck=machine.Pin(2),mosi=machine.Pin(3),miso=machine.Pin(4)).readinto(puter,int(ssebr[n*8:n*8+8],2))
      chrout=str(puter)[12]
      if chrout==chr(92):
        print(ord(chr(int("0x"+(str(puter)[14:16])))),"$",end="")
      if chrout!=chr(92):
        print(ord(str(puter)[12]),"@",end="")
    machine.Pin(0).value(0)    # low latched the data into the display
    machine.Pin(0).value(1)    # high latched the data into the display
    print("")
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT