0

I just bought a Raspberry Pi and I was playing around with an LED, trying to learn Python. So my setup is as follows: my led is is connected to the 7th PIN of my GPIO and to ground. I made the following code:

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
GPIO.output(7, True)
time.sleep(10)
GPIO.output(7, False)
time.sleep(5)
GPIO.output(7, True)

When I ran this code, the LED blinks once for 10 seconds, turns off and nevers turns back on. What can be wrong?

2
  • Do you want it to repeat? Put it into a loop. Commented Feb 23, 2014 at 3:20
  • You may wish to put a resistor in series with the diode to purveyors excessive current being drawn from the gpio. Commented Feb 26, 2014 at 5:40

1 Answer 1

2

Try this:

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
while True:
    GPIO.output(7, True)
    time.sleep(10)
    GPIO.output(7, False)
    time.sleep(5)

It should loop the on/off sequence, causing the light to turn on for 10s, then turn off for 5s, and repeat.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.