0

As a newbie Im testing my Pi 2 B's GPIO. Why doesn't the code below switch the 15 pin on and off with an interval, but keeps it turned on?

import RPi.GPIO as GPIO
import time

     GPIO.setmode(GPIO.BCM)
     GPIO.setup(15, GPIO.OUT)

     for i in range(1000):
         GPIO.output(15,1)
         time.sleep(3)
         GPIO.output(15,0)
         print("switch")

     GPIO.cleanup()
Pang
  • 9,564
  • 146
  • 81
  • 122
Willem-Jan
  • 67
  • 8

1 Answers1

2

Your loop is ill-formed.

You switch ON the GPIO just after switching it OFF.

Fix:

for i in range(1000):
     GPIO.output(15,1)
     time.sleep(1) # ON for one second
     GPIO.output(15,0)
     print("switch")
     time.sleep(1) # sleeping after the switch
Zermingore
  • 743
  • 2
  • 11
  • 28