I have an RGB LED connected to a Raspberry Pi 3 with the below code. What I want to do is present the user with a question to choose Red, Green or Blue, corresponding to a variable linked to specific GPIO pins.
When user enters, Red, the LED will turn red. When they enter Blue, the LED will turn blue.
Currently if I enter red, the code will print '20' (integer), which corresponds to the BCM pin 20. This is good, but my problem is that I'm having trouble converting the user's string response to lowercase first. (i.e., convert RED to red).
I am getting an error:
request = input("Choose a color. Red/Green/Blue".lower())
File "<string>", line 1, in <module>
NameError: name 'Red' is not defined
The code below is at its simplest form to first test that I can get the lowercase input from the user.
red = 20
green = 16
blue = 21
try:
while True:
# I would like to convert user's answer (Red, Green,Blue) to a lowercase answer (ie. red, green blue)
request = input("Choose a color. Red/Green/Blue").lower()
print(type(request))
print(request)
except KeyboardInterrupt:
Any help would be much appreciated.