-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLEDTest.py
More file actions
47 lines (39 loc) · 998 Bytes
/
LEDTest.py
File metadata and controls
47 lines (39 loc) · 998 Bytes
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
import RPi.GPIO as GPIO
import time
# GPIO pin setup
RED_PIN = 12
GREEN_PIN = 13
BLUE_PIN = 19
# Setup GPIO mode
GPIO.setmode(GPIO.BCM)
GPIO.setup(RED_PIN, GPIO.OUT)
GPIO.setup(GREEN_PIN, GPIO.OUT)
GPIO.setup(BLUE_PIN, GPIO.OUT)
# Function to turn off all LEDs
def turn_off_all():
GPIO.output(RED_PIN, GPIO.LOW)
GPIO.output(GREEN_PIN, GPIO.LOW)
GPIO.output(BLUE_PIN, GPIO.LOW)
try:
while True:
# Red LED
print("Red ON")
GPIO.output(RED_PIN, GPIO.HIGH)
time.sleep(1)
GPIO.output(RED_PIN, GPIO.LOW)
# Green LED
print("Green ON")
GPIO.output(GREEN_PIN, GPIO.HIGH)
time.sleep(1)
GPIO.output(GREEN_PIN, GPIO.LOW)
# Blue LED
print("Blue ON")
GPIO.output(BLUE_PIN, GPIO.HIGH)
time.sleep(1)
GPIO.output(BLUE_PIN, GPIO.LOW)
except KeyboardInterrupt:
print("Exiting program...")
finally:
# Clean up GPIO state on exit
turn_off_all()
GPIO.cleanup()