forked from aovtsinn/it
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrgb.py
52 lines (45 loc) · 1.14 KB
/
rgb.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
#! /usr/bin/env python
#
# Set an RGB LED to either red, green, or blue.
#
# Usage:
# sudo python rgb.py [color]
#
# @author Jeff Geerling, 2015
#
# Artur added a comment
import argparse
import RPi.GPIO as GPIO
# Get RGB colors from command line arguments.
parser = argparse.ArgumentParser(description = 'Add a little color to your life.')
parser.add_argument('color', metavar='color', type=str, nargs=1,
help='A color value of red, green, blue, or off.')
args = parser.parse_args()
# LED pin mapping.
red = 10
green = 20
blue = 27
# GPIO Setup.
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(red, GPIO.OUT)
GPIO.setup(green, GPIO.OUT)
GPIO.setup(blue, GPIO.OUT)
# Clear all existing color values.
GPIO.output(red, 0)
GPIO.output(green, 0)
GPIO.output(blue, 0)
# Set individual colors.
if args.color[0] == 'red':
GPIO.output(red, 1)
elif args.color[0] == 'green':
GPIO.output(green, 1)
elif args.color[0] == 'blue':
GPIO.output(blue, 1)
elif args.color[0] == 'yellow':
GPIO.output(red, 0)
GPIO.output(blue, 0)
elif args.color[0] == 'white':
GPIO.output(red, 0)
GPIO.output(blue, 0)
GPIO.output(green, 0)