joystick debugging
user_3789319
plain_text
2 years ago
1.2 kB
6
Indexable
import pygame
from pygame.locals import *
from rpi_ws281x import Adafruit_NeoPixel, Color
# Initialize the LED strip configuration (same as before)
# ...
def change_color():
# Change the color of the LEDs here
color = Color(255, 0, 0) # Red color (you can modify this)
for i in range(LED_COUNT):
strip.setPixelColor(i, color)
strip.show()
# Initialize pygame
pygame.init()
# Initialize the joystick
pygame.joystick.init()
try:
joystick = pygame.joystick.Joystick(0)
joystick.init()
while True:
# Handle events, including button presses
for event in pygame.event.get():
if event.type == JOYBUTTONDOWN:
# Check for specific button presses, adjust as needed
if event.button == 0: # Adjust the button number as needed
change_color()
pygame.time.wait(200) # debounce time to avoid multiple presses
except KeyboardInterrupt:
pass
finally:
# Cleanup GPIO and turn off LEDs on program exit
GPIO.cleanup()
for i in range(LED_COUNT):
strip.setPixelColor(i, Color(0, 0, 0))
strip.show()
Editor is loading...
Leave a Comment