Untitled
user_3789319
plain_text
8 months ago
829 B
2
Indexable
Never
import time import keyboard from rpi_ws281x import Adafruit_NeoPixel, Color # 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() try: while True: # Check for button press if keyboard.is_pressed('a'): # Change 'a' to the key you want to use # Button is pressed, change LED color change_color() time.sleep(0.2) # 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()
Leave a Comment