Skip to content

Commit 9c71ebc

Browse files
...
1 parent 697453a commit 9c71ebc

6 files changed

Lines changed: 96 additions & 0 deletions

File tree

scripts/colour_detection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#!/usr/bin/env python3

scripts/led_test.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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("\nLEDs turned off.")

scripts/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#!/usr/bin/env python3

scripts/tests/servo_test.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
3+
from gpiozero import Servo
4+
from time import sleep
5+
6+
# Hardware Configuration
7+
SERVO0_PIN = 12
8+
SERVO1_PIN = 13
9+
10+
# Initialize Servos
11+
# We use a standard pulse width range (min=1ms, max=2ms)
12+
servo0 = Servo(SERVO0_PIN)
13+
servo1 = Servo(SERVO1_PIN)
14+
15+
def test_sweep(servo_obj, name):
16+
print(f"--- Testing {name} ---")
17+
18+
print("Moving to MIN position...")
19+
servo_obj.min()
20+
sleep(1)
21+
22+
print("Moving to MID position...")
23+
servo_obj.mid()
24+
sleep(1)
25+
26+
print("Moving to MAX position...")
27+
servo_obj.max()
28+
sleep(1)
29+
30+
print("Returning to MID...")
31+
servo_obj.mid()
32+
sleep(0.5)
33+
34+
try:
35+
print("Starting Servo Test...")
36+
test_sweep(servo0, "Servo 0 (Pin 12)")
37+
test_sweep(servo1, "Servo 1 (Pin 13)")
38+
print("Test Complete!")
39+
40+
except KeyboardInterrupt:
41+
print("\nTest stopped by user.")
42+
43+
finally:
44+
# Cleanup
45+
servo0.value = None
46+
servo1.value = None

0 commit comments

Comments
 (0)