from machine import PWM,Pin,ADC,I2C,SoftI2C
from pico_i2c_lcd import I2cLcd
import time
i2c =SoftI2C(sda=Pin(18),scl=Pin(17),freq=40000)
lcd_addr = i2c.scan()[0]
lcd =I2cLcd(i2c,lcd_addr,4,20)
xAxis = machine.ADC(26)
yAxis = ADC(Pin(27))
button = Pin(16,Pin.IN, Pin.PULL_UP)
while True:
xValue = xAxis.read_u16()
yValue = yAxis.read_u16()
buttonValue = button.value()
xStatus = "middle"
yStatus = "middle"
lcd.move_to(8,1)
lcd.putstr("HI")
buttonStatus = "not pressed"
if xValue <= 600:
xStatus = "right"
lcd.clear()
lcd.move_to(19,1)
lcd.putstr("HI")
elif xValue >= 60000:
xStatus = "left"
lcd.clear()
lcd.move_to(0,1)
lcd.putstr("HI")
if yValue <= 600:
yStatus = "top"
lcd.clear()
lcd.move_to(8,0)
lcd.putstr("HI")
elif yValue >= 60000:
yStatus = "down"
lcd.clear()
lcd.move_to(8,2)
lcd.putstr("HI")
if buttonValue == 0:
buttonStatus = "pressed"
print("X: " + xStatus + ", Y: " + yStatus + " -- button " + buttonStatus)
utime.sleep(0.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
joystick1:VCC
joystick1:VERT
joystick1:HORZ
joystick1:SEL
joystick1:GND
lcd2:GND
lcd2:VCC
lcd2:SDA
lcd2:SCL