Untitled
user_3789319
plain_text
2 years ago
829 B
11
Indexable
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()
Editor is loading...
Leave a Comment