-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexample_usage.py
32 lines (28 loc) · 1 KB
/
example_usage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#basic example of using the Pi5Neo class to control a NeoPixel strip
from pi5neo import Pi5Neo # Import the Pi5Neo class
import time
def demo_solid_color(neo, red, green, blue, duration=2):
"""Set the entire strip to a solid color and hold for a duration"""
neo.fill_strip(red, green, blue)
neo.update_strip()
time.sleep(duration)
def demo_rainbow_cycle(neo, delay=0.1):
"""Cycle through rainbow colors on the entire strip"""
rainbow_colors = [
(255, 0, 0), # Red
(255, 127, 0), # Orange
(255, 255, 0), # Yellow
(0, 255, 0), # Green
(0, 0, 255), # Blue
(75, 0, 130), # Indigo
(148, 0, 211) # Violet
]
for color in rainbow_colors:
neo.fill_strip(*color)
neo.update_strip()
time.sleep(delay)
# Initialize the Pi5Neo class with 10 LEDs
pi5_neo = Pi5Neo('/dev/spidev0.0', 10, 800)
# Run demo functions
demo_solid_color(pi5_neo, 255, 0, 0) # Red strip
demo_rainbow_cycle(pi5_neo) # Rainbow cycle effect