-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_led.py
More file actions
82 lines (68 loc) · 2.22 KB
/
test_led.py
File metadata and controls
82 lines (68 loc) · 2.22 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
"""Quick LED strip test script - Run with sudo"""
import sys
import time
print("LED Strip Test Script")
print("=" * 50)
# Test 1: Check if library is available
print("\n1. Checking rpi_ws281x library...")
try:
from rpi_ws281x import PixelStrip, Color
print(" ✓ Library found")
except ImportError as e:
print(f" ✗ Library not found: {e}")
print(" Install with: sudo pip3 install rpi_ws281x")
sys.exit(1)
# Test 2: Initialize strip
print("\n2. Initializing LED strip...")
LED_COUNT = 144 # Number of LED pixels (adjust to your strip)
LED_PIN = 18 # GPIO pin (BCM numbering)
LED_BRIGHTNESS = 128 # Brightness (0-255)
try:
strip = PixelStrip(LED_COUNT, LED_PIN, brightness=LED_BRIGHTNESS)
strip.begin()
print(f" ✓ Strip initialized ({LED_COUNT} LEDs on GPIO {LED_PIN})")
except Exception as e:
print(f" ✗ Initialization failed: {e}")
print("\n Troubleshooting:")
print(" - Are you running with sudo?")
print(" - Is GPIO 18 already in use?")
print(" - Check wiring connections")
sys.exit(1)
# Test 3: Light up LEDs
print("\n3. Testing LEDs...")
print(" This will cycle through: Red → Green → Blue → Off")
colors = [
(Color(255, 0, 0), "Red"),
(Color(0, 255, 0), "Green"),
(Color(0, 0, 255), "Blue"),
]
try:
for color, name in colors:
print(f" → {name}...", end='', flush=True)
for i in range(strip.numPixels()):
strip.setPixelColor(i, color)
strip.show()
time.sleep(1.5)
print(" OK")
# Turn off
print(" → Off...", end='', flush=True)
for i in range(strip.numPixels()):
strip.setPixelColor(i, Color(0, 0, 0))
strip.show()
print(" OK")
print("\n" + "=" * 50)
print("✓ LED strip test PASSED!")
print("\nIf you saw the colors, your hardware is working.")
print("Make sure to enable the LED strip in the web settings.")
print("=" * 50)
except KeyboardInterrupt:
print("\n\nTest interrupted")
except Exception as e:
print(f"\n ✗ Test failed: {e}")
sys.exit(1)
finally:
# Cleanup
for i in range(strip.numPixels()):
strip.setPixelColor(i, Color(0, 0, 0))
strip.show()