from machine import Pin, ADC
import time
# Initialize Joystick Pins
vrx = ADC(26) # X-axis (GP26 / ADC0)
vry = ADC(27) # Y-axis (GP27 / ADC1)
sw = Pin(14, Pin.IN, Pin.PULL_UP) # Switch button (GP14) with pull-up resistor
# Read joystick values
def read_joystick():
x_value = vrx.read_u16() # Read X-axis (0 to 65535)
y_value = vry.read_u16() # Read Y-axis (0 to 65535)
button_pressed = not sw.value() # Read button (LOW when pressed)
# Print values
print(f"X: {x_value}, Y: {y_value}, Button: {'Pressed' if button_pressed else 'Not Pressed'}")
time.sleep(0.1)
# Main loop
while True:
read_joystick()