Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''PROGRAM BY: RANDY N. CAÑADA
- SUBSCRIBE: FB PAGES:
- Playlist.ph:
- https://www.facebook.com/profile.php?id=61573177858722
- Arduino:
- https://www.facebook.com/rhacan2?__tn__=R
- YOUTUBE:
- PlaylistPH
- https://www.youtube.com/@PlaylistPh-h2v
- ElectroCrafters:
- https://www.youtube.com/channel/UCu1aqzUdTqSnTN5BHNlbVgA '''
- from inputs import get_gamepad
- import socket
- import time
- piPico_IP = '' # ← Replace with your Pico W's actual IP
- PORT = 1234
- def connect_socket():
- while True:
- try:
- sock = socket.socket()
- sock.connect((piPico_IP, PORT))
- print(f"✅ Connected to Pico W at {piPico_IP}:{PORT}")
- return sock
- except Exception as e:
- print(f"🔌 Connection failed: {e}")
- time.sleep(3)
- sock = connect_socket()
- try:
- while True:
- events = get_gamepad()
- for event in events:
- code = event.code
- value = event.state
- typ = event.ev_type
- print(f"📥 Event → Code: {code} | Type: {typ} | Value: {value}")
- if typ == 'Absolute':
- if code == 'ABS_RX':
- msg = f"AXIS:ABS_RX:{value}\n"
- elif code == 'ABS_X':
- msg = f"AXIS:ABS_X:{value}\n"
- elif code == 'ABS_Y':
- msg = f"AXIS:ABS_Y:{value}\n"
- elif code == 'ABS_RY':
- msg = f"AXIS:ABS_RY:{value}\n"
- else:
- continue # Skip unknown axis
- try:
- sock.sendall(msg.encode())
- print(f"📤 Sent → {msg.strip()}")
- except Exception as e:
- print(f"⚠️ Send failed: {e}")
- sock.close()
- sock = connect_socket() # Reconnect if needed
- except KeyboardInterrupt:
- print("👋 Shutting down dongle script")
- sock.close()
Advertisement
Add Comment
Please, Sign In to add comment