This repository has been archived by the owner on Feb 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
color_chooser.py
executable file
·87 lines (86 loc) · 2.33 KB
/
color_chooser.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
84
85
86
87
#This isn't much, but this helps to define color codes for different colors!
import random
#Setting up the Pi...
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(00, GPIO.OUT)
GPIO.setup(01, GPIO.OUT)
GPIO.setup(04, GPIO.OUT)
GPIO.output(00, 1)
GPIO.output(01, 1)
GPIO.output(04, 1)
r = GPIO.PWM(00, 60)
g = GPIO.PWM(01, 60)
b = GPIO.PWM(04, 60)
r.start(0)
g.start(0)
b.start(0)
complete = 0
print ("Hello! Just follow the prompts.")
print ("If you're looking for a random color, just hit enter throughout the prompts without entering a number.")
try:
while True:
# r.ChangeDutyCycle(0)
# g.ChangeDutyCycle(0)
# b.ChangeDutyCycle(0)
if complete == 1:
break
while True:
try:
red = input("Choose a value for the Red LED between 0 and 100: ")
if 0 <= red <= 100:
break
else:
print ("I can't compute that. Try again?")
except (ValueError, NameError):
print ("I can't compute that. Try again?")
except SyntaxError:
red = random.randint(0,100)
break
while True:
try:
green = input("Choose a value for the Green LED between 0 and 100: ")
if 0 <= green <= 100:
break
else:
print("I can't compute that. Try again?")
except (ValueError, NameError):
print("I can't compute that. Try again?")
except SyntaxError:
green = random.randint(0,100)
break
while True:
try:
blue = input("Choose a value for the Blue LED between 0 and 100: ")
if 0 <= blue <= 100:
break
else:
print("I can't compute that. Try again?")
except (ValueError, NameError):
print("I can't compute that. Try again?")
except SyntaxError:
blue = random.randint(0,100)
break
print
print("Working...")
r.ChangeDutyCycle(red)
b.ChangeDutyCycle(blue)
g.ChangeDutyCycle(green)
print
print("Great! Take a look at the LED and if you like what you see, jot down these color values:")
print(red, green, blue)
while True:
try:
answer = input("Press Enter to run this again. Otherwise, type 'quit': ")
if answer == quit:
print ("Bye!")
complete = 1
break
except (ValueError, NameError):
continue
except SyntaxError:
break
except KeyboardInterrupt:
print
print("Goodbye!")