# Authored by Jonathan Scott James the great On WOKWI
# LCD 1602 8 bit bitbang For general purpose interface as car tachometer voltage meter chronometer frequency counter waveform monitor for generator
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
ttt=1;t=3600*24*366+28;t=3600*24*22-9 # python sets the precisio level when you first assign the number according to what will fit in the value you assign it to.
k=0;k1=0;b=0;b1=0;              
def tickjsj():
    global t
    t=t+1
machine.Timer().init(period=1000, callback=lambda t:tickjsj())
for initpins in range (11): # Initialize gpio 0 threw gpio 10 as output mode
    machine.Pin(initpins, machine.Pin.OUT) #(e)enable
machine.lightsleep(500)#initialization oause after power up .5 seconds
#init lcd Module
machine.Pin(10).value(0)  # Enable 1=Enable
machine.Pin(9).value(0)#RS instruction=0 data=1
machine.Pin(7).value(0) #d7
machine.Pin(6).value(0) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(0) #d4
machine.Pin(3).value(1) #d3
machine.Pin(2).value(1) #d2
machine.Pin(1).value(0) #d1
machine.Pin(0).value(0) #d0
machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(9).value(1) #RS instruction=0 data=1
#************end init***********************
tt=" "
eightbitsevensegreversed="00111111000001100101101101001111011001100110110101111101000001110111111101101111"
ssebr=eightbitsevensegreversed
k=0;b=0;k2=0;b2=0
puter=bytearray(1)
while 1:#start displat
  k=machine.Pin(28).value()#read pin 28 which is connected to key1
  if (k>b):
    k1=k1+1-4*(k1>3)
  b=k
  k2=machine.Pin(27).value()#read pin 27 which is Connected to key2
  if (k2>b2):
    k1=k1+1-4*(k1>3)
  b2=k2
  rvdc=machine.ADC(26).read_u16() #read adc into variable
  if ttt==t:
    print(end="")
  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 
    #target string 
    af=tt+"T " +"("+str(b)+str(b2)+")"   +str(rvdc)+"VDC"
    #****************
    machine.Pin(9).value(0) #RS instruction=0 data=1
    machine.Pin(7).value(0) #d7
    machine.Pin(6).value(0) #d6
    machine.Pin(5).value(0) #d5
    machine.Pin(4).value(0) #d4
    machine.Pin(3).value(0) #d3
    machine.Pin(2).value(0) #d2
    machine.Pin(1).value(1) #d1 #home instrtction
    machine.Pin(0).value(0) #d0
    machine.Pin(10).value(1)  # Enable 1=Enable
    machine.lightsleep(1)
    machine.Pin(10).value(0)  # Enable 1=Enable
    machine.lightsleep(1)
    machine.Pin(9).value(1)#RS instruction=0 data=1
    for cx in range (len(af)):# print the string one character at a time 
        ds= str("00000000"+bin(ord(af[cx]))[2:12])[-8:17]
        machine.Pin(7).value(int(str(ds)[0])) #d7
        machine.Pin(6).value(int(str(ds)[1])) #d6
        machine.Pin(5).value(int(str(ds)[2])) #d5
        machine.Pin(4).value(int(str(ds)[3])) #d4
        machine.Pin(3).value(int(str(ds)[4])) #d3
        machine.Pin(2).value(int(str(ds)[5])) #d2
        machine.Pin(1).value(int(str(ds)[6])) #d1
        machine.Pin(0).value(int(str(ds)[7])) #d0
        machine.Pin(10).value(1)  # Enable 1=Enable
        machine.lightsleep(1)
        machine.Pin(10).value(0)  # Enable 1=Enable
        machine.lightsleep(1)# slow effect
        if (cx==15):#set cursor to line 2
            machine.Pin(9).value(0)#RS instruction=0 data=1
            machine.Pin(7).value(1) #d7
            machine.Pin(6).value(0) #d6
            machine.Pin(5).value(0) #d5
            machine.Pin(4).value(1) #d4
            machine.Pin(3).value(1) #d3
            machine.Pin(2).value(0) #d2
            machine.Pin(1).value(1) #d1
            machine.Pin(0).value(0) #d0
            machine.Pin(10).value(1)  # Enable 1=Enable
            machine.lightsleep(1)
            machine.Pin(10).value(0)  # Enable 1=Enable
            machine.lightsleep(1)
            machine.Pin(9).value(1)#RS instruction=0 data=1
            for clcks in range(14):# 15 analogous clock cycles required at some point.
                machine.Pin(10).value(1)  # Enable 1=Enable
                machine.lightsleep(1)
                machine.Pin(10).value(0)  # Enable 1=Enable
                machine.lightsleep(1)
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT