I have been working on designing an automotive turn signal device to integrate into a prototype device after development. Currently, I am attempting to write Python script which will use it's GPIO output pins to signal the pins of a micro controller, which will, based on input, decide which set of LED's to blink.
As most people know, there are three states in a automotive turn signal device, which I will describe as:
- No_Turn
- Left_Turn
- Right_Turn
Most tutorials only describe how to get one set of LED's to blink, but that won't be good enough for this project. Not only do I need more than one set of LED's to blink, but also there is a time they don't need to blink.
To arrive at my algorithm, I tried to adjust the simple code for a typical blink LED sketch, yet now, I'm using the conditions of two GPIO input pins,GPIO 24 & 25,to determine output in the the loop
I need to loop based on the conditions of two different inputs. Here is the code I am using to try to implement this:
#Step_1: Initialize script with necessary imports and setup pins
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(24,GPIO.IN)
GPIO.setup(25,GPIO.IN)
GPIO.setup(18,GPIO.OUT)
GPIO.setup(17,GPIO.OUT)
#Step_2: I would like to loop continuously as the states of my inputs may
#change(I'm driving, imagine driving through the nice country roads :))
try:
while True:
GPIO.input(24,False) #This is the first state: No_Signal if
if(GPIO.input(25)==False):#both inputs are LOW, then both outputs
GPIO.output(18,False) #should be low.
GPIO.output(17,False)
else:
GPIO.input(24,True) #This is the second state: Left_Turn.
if(GPIO.input(25)==False): # If input 24 is HIGH, and 25 LOW,
GPIO.output(18,False) # Then output 18 LOW, 17 HIGH.
GPIO.output(17,True)
else:
GPIO.input(24,False) # This is the third state: Right_Turn
if(GPIO.input(25)==True): # If input 24 LOW, and 25 HIGH,
GPIO.output(18,True) # Then output 18 HIGH, 17 LOW.
GPIO.output(17,False)
finally:
GPIO.cleanup()
exit()
SyntaxError: Line 21; else:
Basically, my solution, or algorithm, to get two different sets of LED's to blink at different times, is to define output based on the current state of two inputs. It be nice if I could do that with one input, but I thought deeply for a while an couldn't see how that could be possible, or at least practical.
Problem right now is >>>>> SyntaxError: Line 21; else:
I keep getting invalid syntax errors, but I know sometimes Error returns are generic, and don't indicate the actual problem, so it could be the syntax or some of the code itself.
And for some weird reason, when I move my code from laptop to pi, each IDE or editor keeps changing my code!Each one moves else indentation, even though I din't save it that way.
Does anybody know why this isn't working? Thank you.
CONCLUSION
I'd like to give a huge thanks to Scitronboy and Ghanima to help me edit my code. It works perfectly now.