I'm writing a program to run on my Raspberry Pi, and I can't seem to get past this pesty syntax error. Here's my code:
import RPi.GPIO as GPIO, time
GPIO.setmode(GPIO.BCM)
GPIO.setup(14,GPIO.OUT)
GPIO.output(14,GPIO.HIGH)
def RCtime (PiPin):
measurement = 0
# Discharge capacitor
GPIO.setup(PiPin, GPIO.OUT)
GPIO.output(PiPin, GPIO.LOW)
time.sleep(0.1)
GPIO.setup(PiPin, GPIO.IN)
# Count loops until voltage across
# capacitor reads high on GPIO
while (GPIO.input(PiPin) == GPIO.LOW):
measurement += 1
return measurement
# Main program loop
while True:
print RCtime(4) # Measure timing using GPIO4
except KeyboardInterrupt:
GPIO.cleanup()
Returns the following error:
File "measure.py", line 28
except KeyboardInterrupt:
^
SyntaxError: invalid syntax
I can't seem to find the problem. Can anyone help?
trypart of thetry-exceptstatement.try...finallyinstead anyway. That way if the program exits normally (not possible in this program, but is in others) the cleanup still happens. Also you don't lose your error, which helps a lot when it comes to debugging...