# 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.
def tickjsj():
    global t
    t=t+1
machine.Timer().init(period=1000, callback=lambda t:tickjsj())

machine.Pin(10, machine.Pin.OUT) #(e)enable
machine.Pin(9, machine.Pin.OUT) #(rs)register select
machine.Pin(8, machine.Pin.OUT) #(r/w)read/weite 
machine.Pin(7, machine.Pin.OUT) #(d7)data bit7
machine.Pin(6, machine.Pin.OUT) #(d6)data bit6
machine.Pin(5, machine.Pin.OUT) #(d5)data bit5
machine.Pin(4, machine.Pin.OUT) #(d4)data bit4
machine.Pin(3, machine.Pin.OUT) #(d3)data bit3
machine.Pin(2, machine.Pin.OUT) #(d2)data bit2
machine.Pin(1, machine.Pin.OUT) #(d1)data bit1 
machine.Pin(0, machine.Pin.OUT) #(d0)data bit0
#*******************************************
#send initialization sequence by bit banging wurg the gpio
machine.lightsleep(500)
#  Display ON/OFF
# rs rw d7 d6 d5 d4 d3 d2 d1 d0
# 0  0  0  0  0  0  1  D  C  B
#  (D)display ON/OFF  (C)cursorON/OFF  (B)blink cursor
#   D=1:display ON;D=0:display OFF.C=1:cursor ON;C=0:cursor OFF.B=1:blink cursor ON;B=0:blink cursor OFF.
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(1) #d1
machine.Pin(0).value(1) #d0
machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)
# done
#**********************************
#  Write character to dispay at current position then incrimnent/dectiment CG/DDRAM
# rs  rw  d7  d6  d5  d4  d3  d2  d1  d0
# 1   0   d0  d1  d2  d3  d4  d5  d6  d7
#
# Display this string Of 32 characters 0123456789 ABCDEFGHIJ KLMNOPQRST UV

#  Function  Set 
# rs rw d7 d6 d5 d4 d3 d2 d1 d0
# 0  0  0  0  1  DL N  F  x  x # dl=
#  DL=1: 8bit; DL=0: 4bits
#  N=1: 2line; N=0: 1lines
#  F=1: 5x10 characters; F=0: 5x7 characters

machine.Pin(8).value(0)#R/W 1=R 0=W
machine.Pin(9).value(0)#RS instruction=0 data=1
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(7).value(0) #d7
machine.Pin(6).value(0) #d6
machine.Pin(5).value(1) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(1) #d3
machine.Pin(2).value(0) #d2
machine.Pin(1).value(0) #d1
machine.Pin(0).value(0) #d0
machine.lightsleep(1)
machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)

#TURN ON DATA MODE
machine.Pin(9).value(1) # RS instruction=0 data=1

#***********************************
#***********************************
#***********************************
#***********************************
af="The Quick Brown Fox jumped over the lazy dog"
for cx in range (len(af)):
    ds= str("00000000"+bin(ord(af[cx]))[2:12])[-8:17]
    print(ds)
    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(100)
    #------------------------------
    #  Set DDRAM Address 
    if (cx==15):
        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 dummy in range(14):
            machine.Pin(10).value(1)  # Enable 1=Enable
            machine.lightsleep(1)
            machine.Pin(10).value(0)  # Enable 1=Enable
            machine.lightsleep(1)
machine.lightsleep(1000)
machine.lightsleep(1000)
#***********************************
#***********************************
# ClearDisplay
# rs rw d7 d6 d5 d4 d3 d2 d1 d0
# 0  0  0  0  0  0  0  0  0  1 
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(0) #d1
machine.Pin(0).value(1) #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

#***********************************
#***********************************
#***********************************

#0
machine.Pin(7).value(0) #d7
machine.Pin(6).value(0) #d6
machine.Pin(5).value(1) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(0) #d3
machine.Pin(2).value(0) #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)


#1

machine.Pin(7).value(0) #d7
machine.Pin(6).value(0) #d6
machine.Pin(5).value(1) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(0) #d3
machine.Pin(2).value(0) #d2
machine.Pin(1).value(0) #d1
machine.Pin(0).value(1) #d0

machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)

#2
machine.Pin(7).value(0) #d7
machine.Pin(6).value(0) #d6
machine.Pin(5).value(1) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(0) #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)

#3
machine.Pin(7).value(0) #d7
machine.Pin(6).value(0) #d6
machine.Pin(5).value(1) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(0) #d3
machine.Pin(2).value(0) #d2
machine.Pin(1).value(1) #d1
machine.Pin(0).value(1) #d0

machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)

#4
machine.Pin(7).value(0) #d7
machine.Pin(6).value(0) #d6
machine.Pin(5).value(1) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(0) #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)

#5
machine.Pin(7).value(0) #d7
machine.Pin(6).value(0) #d6
machine.Pin(5).value(1) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(0) #d3
machine.Pin(2).value(1) #d2
machine.Pin(1).value(0) #d1
machine.Pin(0).value(1) #d0

machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)

#6
machine.Pin(7).value(0) #d7
machine.Pin(6).value(0) #d6
machine.Pin(5).value(1) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(0) #d3
machine.Pin(2).value(1) #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)
#7
machine.Pin(7).value(0) #d7
machine.Pin(6).value(0) #d6
machine.Pin(5).value(1) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(0) #d3
machine.Pin(2).value(1) #d2
machine.Pin(1).value(1) #d1
machine.Pin(0).value(1) #d0

machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)

#8
machine.Pin(7).value(0) #d7
machine.Pin(6).value(0) #d6
machine.Pin(5).value(1) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(1) #d3
machine.Pin(2).value(0) #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)

#9
machine.Pin(7).value(0) #d7
machine.Pin(6).value(0) #d6
machine.Pin(5).value(1) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(1) #d3
machine.Pin(2).value(0) #d2
machine.Pin(1).value(0) #d1
machine.Pin(0).value(1) #d0

machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)
#A
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #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(0) #d1
machine.Pin(0).value(1) #d0

machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)
#B
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #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
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)
#c
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #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
machine.Pin(0).value(1) #d0

machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)

#D
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(0) #d4
machine.Pin(3).value(0) #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)

#E
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(0) #d4
machine.Pin(3).value(0) #d3
machine.Pin(2).value(1) #d2
machine.Pin(1).value(0) #d1
machine.Pin(0).value(1) #d0
machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)


#F
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(0) #d4
machine.Pin(3).value(0) #d3
machine.Pin(2).value(1) #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)

#------------------------------
#  Set DDRAM Address 
# 0   0   1   AC6 AC5 AC4 AC3 AC2 AC1 AC0 
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
machine.lightsleep(1)
for dymmy2 in range(14):
    machine.lightsleep(1)
    machine.Pin(10).value(1)  # Enable 1=Enable
    machine.lightsleep(1)
    machine.Pin(10).value(0)  # Enable 1=Enable

#***********************************
#G
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(0) #d4
machine.Pin(3).value(0) #d3
machine.Pin(2).value(1) #d2
machine.Pin(1).value(1) #d1
machine.Pin(0).value(1) #d0
machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)


#H
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(0) #d4
machine.Pin(3).value(1) #d3
machine.Pin(2).value(0) #d2
machine.Pin(1).value(0) #d1
machine.Pin(0).value(0) #d0
machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(10)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(10)


#I
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(0) #d4
machine.Pin(3).value(1) #d3
machine.Pin(2).value(0) #d2
machine.Pin(1).value(0) #d1
machine.Pin(0).value(1) #d0
machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(10)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(10)

#J
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(0) #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)

#K
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(0) #d4
machine.Pin(3).value(1) #d3
machine.Pin(2).value(0) #d2
machine.Pin(1).value(1) #d1
machine.Pin(0).value(1) #d0
machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)

#L
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #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)

#M
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #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(1) #d0
machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)

#N
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #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(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)

#O
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #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(1) #d1
machine.Pin(0).value(1) #d0
machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)

#P
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(0) #d3
machine.Pin(2).value(0) #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)

#S
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(0) #d3
machine.Pin(2).value(0) #d2
machine.Pin(1).value(0) #d1
machine.Pin(0).value(1) #d0
machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)

#R
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(0) #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)

#S
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(0) #d3
machine.Pin(2).value(0) #d2
machine.Pin(1).value(1) #d1
machine.Pin(0).value(1) #d0
machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)

#T
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(0) #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)

#U
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(0) #d3
machine.Pin(2).value(1) #d2
machine.Pin(1).value(0) #d1
machine.Pin(0).value(1) #d0
machine.Pin(10).value(1)  # Enable 1=Enable
machine.lightsleep(1)
machine.Pin(10).value(0)  # Enable 1=Enable
machine.lightsleep(1)

#V
machine.Pin(7).value(0) #d7
machine.Pin(6).value(1) #d6
machine.Pin(5).value(0) #d5
machine.Pin(4).value(1) #d4
machine.Pin(3).value(0) #d3
machine.Pin(2).value(1) #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.lightsleep(10000)

# 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(1)
  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("")

#**********************************


# #  Function  Set 
# # rs rw d7 d6 d5 d4 d3 d2 d1 d0
# # 0  0  0  0  1  DL N  F  x  x
# #  Set the interface data length(DL). Number of display lines(N). character font(F). data buss bits (DL)
# #  DL=1: 8 bits ; DL=0: 4bits.
# #  N=1: 2 lines ; N=0: 1 lines.
# #  F=1:5x10dot characters ; F=0:5x7dot.
# machine.Pin(7).value(0) #d7
# machine.Pin(6).value(0) #d6
# machine.Pin(5).value(1) #d5
# machine.Pin(4).value(1) #d4
# machine.Pin(3).value(1) #d3
# machine.Pin(2).value(0) #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)

# # #  Home
# # # rs rw d7 d6 d5 d4 d3 d2 d1 d0
# # # 0  0  0  0  0  0  0  0  1  x 
# # #  Return the cursor to the home position.
# # 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
# # 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)

# #  Cursoror Display shift(inserts a space charaster without changing mode back and forth)
# # rs rw d7 d6 d5 d4 d3 d2 d1 d0
# # 0  0  0  0  0  1 S/C R/L x x
# #  S/C=1:Display shift;S/C=0:Cursor move.R/L=1:shift to right;R/L=0:shift to left.
# machine.Pin(7).value(0) #d7
# machine.Pin(6).value(0) #d6
# machine.Pin(5).value(0) #d5
# machine.Pin(4).value(1) #d4
# machine.Pin(3).value(0) #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

# Only the stuff between these line is added. If you delete everything if you delight if you delete this line and everything above it then it'll be back to normal the way it was working.
# af="the quick brown fox The Quick Brown Fox jumped over the lazy dog"
# for cx in range (len(af)):
#     print(str("00000000"+bin(ord(af[cx]))[2:12])[-8:17]," ",end="")
    
#     for cx in range (100):
#         machine.lightsleep(1)
# machine.lightsleep(5000)
# Only the stuff between these line is added. If you delete everything if you delight if you delete this line and everything above it then it'll be back to normal the way it was working.


#instructions abd their formats
#*****************************
#  ClearDisplay
# rs rw d7 d6 d5 d4 d3 d2 d1 d0
# 0  0  0  0  0  0  0  0  0  1 
#  Clears entire display and returns the cursor to home position(address0).
#****************************
#  Home
# rs rw d7 d6 d5 d4 d3 d2 d1 d0
# 0  0  0  0  0  0  0  0  1  x 
#  Return the cursor to the home position.Also returns the
#  display being shifted to the original position.DDRAM
#  contents remain unchanged.
#****************************
#  Entrymode set (direction insert)
# rs rw d7 d6 d5 d4 d3 d2 d1 d0
# 0  0  0  0  0  0  0  1 I/D S
#  left to righ and insert whriteover(normal i/d=1 s=0)
#  (I/D=1:increment I/D=0:decrement)(S=0 write over S=1:insert)
#****************************
#  Display ON/OFF
# rs rw d7 d6 d5 d4 d3 d2 d1 d0
# 0  0  0  0  0  0  1  D  C  B
#  (D)display ON/OFF  (C)cursorON/OFF  (B)blink cursor
#   D=1:display ON;D=0:display OFF.C=1:cursor ON;C=0:cursor OFF.B=1:blink cursor ON;B=0:blink cursor OFF.
#****************************
#  Cursoror Display shift(inserts a space charaster without changing mode back and forth)
# rs rw d7 d6 d5 d4 d3 d2 d1 d0
# 0  0  0  0  0  1 S/C R/L x x
#  Move the cursor and shift the display without changing DDRAM contents.
#  S/C=1:Display shift;S/C=0:Cursor move.R/L=1:shift to right;R/L=0:shift to left.
#****************************
#  Function  Set 
# rs rw d7 d6 d5 d4 d3 d2 d1 d0
# 0  0  0  0  1  DL N  F  x  x
#  Set the interface data length(DL). Number of display lines(N). character font(F). data buss bits (DL)
#  DL=1: 8 bits ; DL=0: 4bits.
#  N=1: 2 lines ; N=0: 1 lines.
#  F=1: 5dot x 10dot characters ; F=0: 5dot x 7dot characters.
#****************************
#  Set CGRAM address
# rs  rw  d7  d6  d5  d4  d3  d2  d1  d0
# 0   0   0   1   cA0 cA1 cA2 cA3 cA4 cA5
#  custom character(CGRAM) address. Custom characters patterns are stored in these bytes. Is how to define a custom character.
#****************************
#  Set DDRAM Address 
# rs  rw  d7  d6  d5  d4  d3  d2  d1  d0
# 0   0   1   AC6 AC5 AC4 AC3 AC2 AC1 AC0 
#  Set position in display where next character will ve written DDRAM address in address counter
#****************************
#  Readbusy flag & address
# rs  rw  d7  d6  d5  d4  d3  d2  d1  d0
# 0   1   BF  AC6 AC5 AC4 AC3 AC2 AC1 AC0 
#  Reads BusyFlag(BF) indicating internal operationis being performed and reads address counter contents.
#  BF=1:internally operating. 0:can accept instructions
#****************************
#  Write character to dispay at current position then incrimnent/dectiment CG/DDRAM
# rs  rw  d7  d6  d5  d4  d3  d2  d1  d0
# 1   0   d0  d1  d2  d3  d4  d5  d6  d7
#  Writes character code to dispay then incrimnent/dectiment position
#****************************
#  Reads character code from dispay at current position ,, then maybe incrimnent/dectiment CG/DDRAM
# rs  rw  d7  d6  d5  d4  d3  d2  d1  d0
# 1   1   d0  d1  d2  d3  d4  d5  d6  d7
#  reads character code from current dispay Position ,, then maybe incrimnent/dectiment position
#****************************
#****************************
# https://hades.mech.northwestern.edu/images/f/f7/LCD16x2_HJ1602A.pdf
# SEARCH FOR "15.24-bitoperation(4-bit,1line)""

# *********************************************
# LCD1602 initialization sequence
# put pins in output mode
# machine.Pin(10, machine.Pin.OUT, machine.Pin.PULL_DOWN) #(e)enable
# machine.Pin(9, machine.Pin.OUT, machine.Pin.PULL_DOWN) #(rs)register select
# machine.Pin(8, machine.Pin.OUT, machine.Pin.PULL_DOWN) #(r/w)read/weite 
# machine.Pin(7, machine.Pin.OUT, machine.Pin.PULL_DOWN) #(d7)data bit7
# machine.Pin(6, machine.Pin.OUT, machine.Pin.PULL_DOWN) #(d6)data bit6
# machine.Pin(5, machine.Pin.OUT, machine.Pin.PULL_DOWN) #(d5)data bit5
# machine.Pin(4, machine.Pin.OUT, machine.Pin.PULL_DOWN) #(d4)data bit4
# machine.Pin(3, machine.Pin.OUT, machine.Pin.PULL_DOWN) #(d3)data bit3
# machine.Pin(2, machine.Pin.OUT, machine.Pin.PULL_DOWN) #(d2)data bit2
# machine.Pin(1, machine.Pin.OUT, machine.Pin.PULL_DOWN) #(d1)data bit1 
# machine.Pin(0, machine.Pin.OUT, machine.Pin.PULL_DOWN) #(d0)data bit0

#
#initialization sequence bytes in bynary
# rs rw d7 d6 d5 d4 d3 d2 d1 d0 #R/W 1=R 0=W
# 0  0  0  0  1  1  0  0  0  0
# 0  0  0  0  1  1  0  0  0  0
# 0  0  0  0  1  1  0  0  0  0

# rs rw d7 d6 d5 d4 d3 d2 d1 d0 #R/W 1=R 0=W
# 0  0  0  0  1  1  1  1  0  0  #LARGE FONT 2 LINES
# 0  0  0  0  0  0  1  0  0  0  #
# 0  0  0  0  0  0  0  0  0  1  #
# 0  0  1  0  0  0  0  0  0  0  #
# 0  0  0  0  0  0  0  1  1  0  # incriment, write over (not insert text)


#DEC HEX BIN    Symbol
#       76543210
# 32 20 00100000 ␠
# 33 21 00100001 !
# 34 22 00100010 "
# 35 23 00100011 #
# 36 24 00100100 $
# 37 25 00100101 %
# 38 26 00100110 &
# 39 27 00100111 '
# 40 28 00101000 (
# 41 29 00101001 )
# 42 2A 00101010 *
# 43 2B 00101011 +
# 44 2C 00101100 ,
# 45 2D 00101101 -
# 46 2E 00101110 .
# 47 2F 00101111 /
# 48 30 00110000 0
# 49 31 00110001 1
# 50 32 00110010 2
# 51 33 00110011 3
# 52 34 00110100 4
# 53 35 00110101 5
# 54 36 00110110 6
# 55 37 00110111 7
# 56 38 00111000 8
# 57 39 00111001 9
# 58 3A 00111010 :
# 59 3B 00111011 ;
# 60 3C 00111100 <
# 61 3D 00111101 =
# 62 3E 00111110 >
# 63 3F 00111111 ?
# 64 40 01000000 @
# 65 41 01000001 A
# 66 42 01000010 B 
# 67 43 01000011 C
# 68 44 01000100 D
# 69 45 01000101 E
# 70 46 01000110 F
# 71 47 01000111 G
# 72 48 01001000 H
# 73 49 01001001 I
# 74 4A 01001010 J
# 75 4B 01001011 K
# 76 4C 01001100 L
# 77 4D 01001101 M
# 78 4E 01001110 N
# 79 4F 01001111 O
# 80 50 01010000 P
# 81 51 01010001 Q
# 82 52 01010010 R
# 83 53 01010011 S
# 84 54 01010100 T
# 85 55 01010101 U
# 86 56 01010110 V
# 87 57 01010111 W
# 88 58 01011000 X
# 89 59 01011001 Y
# 90 5A 01011010 Z
# 91 5B 01011011 [
# 92 5C 01011100 \
# 93 5D 01011101 ]
# 94 5E 01011110 ^
# 95 5F 01011111 _
# 96 60 01100000 `
# 97 61 01100001 a
# 98 62 01100010 b
# 99 63 01100011 c
# 100 64 01100100 d
# 101 65 01100101 e
# 102 66 01100110 f
# 103 67 01100111 g
# 104 68 01101000 h
# 105 69 01101001 i
# 106 6A 01101010 j
# 107 6B 01101011 k
# 108 6C 01101100 l
# 109 6D 01101101 m
# 110 6E 01101110 n
# 111 6F 01101111 o
# 112 7001110000 p
# 113 71 01110001 q
# 114 72 01110010 r
# 115 73 01110011 s
# 116 74 01110100 t
# 117 75 01110101 u
# 118 76 01110110 v
# 119 77 01110111 w
# 120 78 01111000 x
# 121 79 01111001 y
# 122 7A 01111010 z
# 123 7B 01111011 {
# 124 7C 01111100 |
# 125 7D 01111101 }
# 126 7E 01111110 ~
# 127 7F 01111111 ␡

BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT