# from joystick import Joystick
# from servo import Servo
# import time
# # Initialize the joystick
# joystick = Joystick(xAxis=34, yAxis=35) # Use GPIO 34 for x-axis, GPIO 35 for y-axis
# # Initialize the servos
# servo_pan = Servo(pin=18) # Use GPIO 18 for pan servo
# servo_tilt = Servo(pin=19) # Use GPIO 19 for tilt servo
# # Main loop to test joystick and servo control
# while True:
# # Read joystick state
# joystick_state = joystick.read()
# print(joystick_state)
# # Control the servos based on joystick state
# if joystick_state == 'L':
# servo_pan.left(5) # Move pan servo 5 degrees to the left
# elif joystick_state == 'R':
# servo_pan.right(5) # Move pan servo 5 degrees to the right
# elif joystick_state == 'U':
# servo_tilt.left(5) # Move tilt servo 5 degrees up
# elif joystick_state == 'D':
# servo_tilt.right(5) # Move tilt servo 5 degrees down
# elif joystick_state == 'M':
# print("Joystick in the middle position.")
# # Add a small delay to prevent overloading the loop
# time.sleep(0.5)
from joystick import Joystick
import time
print("hello world")
# Initialize the joystick
joystick = Joystick(xAxis=34, yAxis=35, buttonPin=32, mode='polling') # GPIO 34, 35 for axes; GPIO 32 for button
while True:
# Read joystick state
joystick_state = joystick.read()
# Check joystick button
button_pressed = joystick.is_button_pressed()
# Print joystick state
if joystick_state == 'L':
print("Joystick moved Left")
elif joystick_state == 'R':
print("Joystick moved Right")
elif joystick_state == 'U':
print("Joystick moved Up")
elif joystick_state == 'D':
print("Joystick moved Down")
elif joystick_state == 'M':
print("Joystick in the middle position")
# Print button state
if button_pressed:
print("Joystick button pressed")
# Small delay to prevent flooding the output
time.sleep(0.1)