-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrgbled.py
executable file
·83 lines (79 loc) · 1.78 KB
/
rgbled.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
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
80
81
82
83
#!/usr/bin/python3
# Import required Python libraries
import RPi.GPIO as GPIO
import time
# Set the Variables
# set red,green and blue pins
redPin = 22
greenPin = 27
bluePin = 17
# Configuration
# disable warnings (optional)
GPIO.setwarnings(False)
# Select GPIO Mode
GPIO.setmode(GPIO.BCM)
# set pins as outputs
GPIO.setup(redPin,GPIO.OUT)
GPIO.setup(greenPin,GPIO.OUT)
GPIO.setup(bluePin,GPIO.OUT)
# Functions
def turnOff():
GPIO.output(redPin,GPIO.LOW)
GPIO.output(greenPin,GPIO.LOW)
GPIO.output(bluePin,GPIO.LOW)
def white():
GPIO.output(redPin,GPIO.HIGH)
GPIO.output(greenPin,GPIO.HIGH)
GPIO.output(bluePin,GPIO.HIGH)
def red():
GPIO.output(redPin,GPIO.HIGH)
GPIO.output(greenPin,GPIO.LOW)
GPIO.output(bluePin,GPIO.LOW)
def green():
GPIO.output(redPin,GPIO.LOW)
GPIO.output(greenPin,GPIO.HIGH)
GPIO.output(bluePin,GPIO.LOW)
def blue():
GPIO.output(redPin,GPIO.LOW)
GPIO.output(greenPin,GPIO.LOW)
GPIO.output(bluePin,GPIO.HIGH)
def yellow():
GPIO.output(redPin,GPIO.HIGH)
GPIO.output(greenPin,GPIO.HIGH)
GPIO.output(bluePin,GPIO.LOW)
def purple():
GPIO.output(redPin,GPIO.HIGH)
GPIO.output(greenPin,GPIO.LOW)
GPIO.output(bluePin,GPIO.HIGH)
def lightBlue():
GPIO.output(redPin,GPIO.LOW)
GPIO.output(greenPin,GPIO.HIGH)
GPIO.output(bluePin,GPIO.HIGH)
# do the stuff
while True:
try:
print("Press CTRL+C to exit")
turnOff()
time.sleep(1)
white()
time.sleep(1)
red()
time.sleep(1)
green()
time.sleep(1)
blue()
time.sleep(1)
yellow()
time.sleep(1)
purple()
time.sleep(1)
lightBlue()
time.sleep(1)
except KeyboardInterrupt:
print("Goodbye!")
turnOff()
exit (0)
except :
print("An Error accured ... ")
time.sleep(1)
continue