2

I'm trying to make a led blink every second. This is my code:

import RPi.GPIO as gpio
try:
    while True:
        gpio.output(20, 1)
        time.sleep(1)
        gpio.output(20, 0)
except KeyboardInterrupt:
        gpio.cleanup()

The problem is that my LED just turns on and it does not blink.

1 Answer 1

4

You don't sleep after you do gpio.output(20, 0). Thus, it instantly turns back on when it repeats the while loop. Do this:

while True:
    gpio.output(20, 1)
    time.sleep(1)
    gpio.output(20, 0)
    time.sleep(1)
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.