Jake Armstrong Jake Armstrong - 1 year ago 65
Python Question

Raspberry Pi 2 Model B is preventing my def function

I have a raspberry Pi 2 Model B. I am trying to make a program that turns on an LED when the input is 'Yes'. What happens is that I get a syntax error saying that def was the error with the arrow pointing at the f. Here is my code:

import RPi.GPIO as GPIO
import time


GPIO.setup(40, GPIO.OUT)

GPIO.setup(38, GPIO.OUT)

GPIO.output(38, 1)

def start():
main(input("> ")

def main(yn):
while True:
if yn == 'Yes':
GPIO.output(40, 1)
print("The LED is on!")
if yn == 'No':
GPIO.output(40, 0)
print("The LED is off!")

Please help and thank you in advance!

Answer Source

Your start function is missing a closing parenthesis:

def start():
    main(input("> "))