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)