Marshal
Marshal

Reputation: 1237

"time" Invalid Syntax Python

Ok so recently been given a Raspberry Pi to tinker with, so after playing with it; installing XBMC, installing Quake 3 arena - I thought I might start making an LED flash.

So I set it all up; turned the LED on and then thought I would take it further and make it blink so below is the code

    import RPi.GPIO as GPIO
    import time
    def blink(pin):
     GPIO.output(pin,GPIO.HIGH
     time.sleep(1)
     GPIO.output(pin,GPIO.LOW)
     time.sleep(1)
            return
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(7, GPIO.OUT)
        for i in range(0,50):
            blink(7)
            GPIO.cleanup()

So when I go to run this it closes and says "Invalid Syntax" and points to the word time so line 5 "time.sleep(1)" it highlights the word "time". I thought this might be a common problem so looking on Google, I find nothing. Anyone have any ideas? perhaps I forgot to install a package; if so which one?

Many thanks,

Upvotes: 0

Views: 5618

Answers (2)

Maxime Lorant
Maxime Lorant

Reputation: 36181

You forget a closing parenthesis at the fourth line:

 GPIO.output(pin,GPIO.HIGH

has to be:

 GPIO.output(pin,GPIO.HIGH)

Your code, with the correct indentation:

import RPi.GPIO as GPIO
import time
def blink(pin):
    GPIO.output(pin,GPIO.HIGH)
    time.sleep(1)
    GPIO.output(pin,GPIO.LOW)
    time.sleep(1)
    return

if __name__ == "__main__":
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(7, GPIO.OUT)
    for i in range(0,50):
        blink(7)
        GPIO.cleanup()

Upvotes: 2

ChrisProsser
ChrisProsser

Reputation: 13108

I think the problem is that you are not closing your brackets on the line:

GPIO.output(pin,GPIO.HIGH

time would be highlighted as an error as the interpretor would expect this to still be part of the parameter list for the previous statement.

Upvotes: 3

Related Questions