# 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)
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
lcd1:VSS
lcd1:VDD
lcd1:V0
lcd1:RS
lcd1:RW
lcd1:E
lcd1:D0
lcd1:D1
lcd1:D2
lcd1:D3
lcd1:D4
lcd1:D5
lcd1:D6
lcd1:D7
lcd1:A
lcd1:K
r1:1
r1:2
vcc1:VCC
r2:1
r2:2
r3:1
r3:2
r4:1
r4:2
r5:1
r5:2
r6:1
r6:2
r7:1
r7:2
r8:1
r8:2
r9:1
r9:2
r10:1
r10:2
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r
btn3:1.l
btn3:2.l
btn3:1.r
btn3:2.r
r11:1
r11:2
r12:1
r12:2
pot1:GND
pot1:SIG
pot1:VCC
led1:A
led1:C
led2:A
led2:C
led4:A
led4:C
led5:A
led5:C
led6:A
led6:C
led7:A
led7:C
led8:A
led8:C
led10:A
led10:C
led9:A
led9:C
led3:A
led3:C