1+ #!/usr/bin/env python3
2+
3+ import time
4+ from rpi_ws281x import PixelStrip , Color
5+
6+ # LED strip configuration:
7+ LED_COUNT = 3 # Number of LED pixels on your HAT
8+ LED_PIN = 10 # GPIO pin connected to the pixels
9+ LED_FREQ_HZ = 800000 # LED signal frequency (800khz)
10+ LED_DMA = 10 # DMA channel to use for generating signal
11+ LED_BRIGHTNESS = 150 # Set to 0 for darkest and 255 for brightest
12+ LED_INVERT = False # True to invert the signal
13+ LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53
14+
15+ def color_wipe (strip , color , wait_ms = 50 ):
16+ """Wipe color across display a pixel at a time."""
17+ for i in range (strip .numPixels ()):
18+ strip .setPixelColor (i , color )
19+ strip .show ()
20+ time .sleep (wait_ms / 1000.0 )
21+
22+ if __name__ == "__main__" :
23+ # Create PixelStrip object
24+ strip = PixelStrip (LED_COUNT , LED_PIN , LED_FREQ_HZ , LED_DMA , LED_INVERT , LED_BRIGHTNESS , LED_CHANNEL )
25+ strip .begin ()
26+
27+ print ("Starting LED Test... Press Ctrl+C to stop." )
28+ try :
29+ while True :
30+ print ("Red" )
31+ color_wipe (strip , Color (255 , 0 , 0 )) # Red
32+ time .sleep (1 )
33+
34+ print ("Green" )
35+ color_wipe (strip , Color (0 , 255 , 0 )) # Green
36+ time .sleep (1 )
37+
38+ print ("Blue" )
39+ color_wipe (strip , Color (0 , 0 , 255 )) # Blue
40+ time .sleep (1 )
41+
42+ print ("Rainbow Cycle" )
43+ color_wipe (strip , Color (255 , 255 , 255 )) # White
44+ time .sleep (1 )
45+
46+ except KeyboardInterrupt :
47+ color_wipe (strip , Color (0 , 0 , 0 ), 10 )
48+ print ("\n LEDs turned off." )
0 commit comments