Reputation: 31
Hi I am trying to run a small python program to control the gpio headers on the raspberry pi and I want it to wait 1 second before turning on each led but instead of sleeping in between each led it waits and sleeps at the end instead (it sleeps for the total 3 seconds which is all the seconds added up).Here is the code I am using
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(True)
GPIO.setup(18,GPIO.OUT)
GPIO.setup(23,GPIO.OUT)
GPIO.setup(24,GPIO.OUT)
print"Lights"
GPIO.output(18,GPIO.HIGH)
time.sleep(1)
GPIO.output(23,GPIO.HIGH)
time.sleep(1)
GPIO.output(24,GPIO.HIGH)
time.sleep(1)
GPIO.cleanup()
Upvotes: 3
Views: 4245
Reputation: 16549
The initial delay may just be setup time.
Based on http://sourceforge.net/p/raspberry-gpio-python/wiki/BasicUsage/ try
GPIO.setup(channel, GPIO.OUT, initial=GPIO.LOW)
To set them initially off.
i.e.
GPIO.setup(18, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(23, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(24, GPIO.OUT, initial=GPIO.LOW)
Upvotes: 2
Reputation: 59691
It appears that
GPIO.setup(18,GPIO.OUT)
GPIO.setup(23,GPIO.OUT)
GPIO.setup(24,GPIO.OUT)
is turning on your LED's, not
GPIO.output(24,GPIO.HIGH)
Make sure you put your print statements between the GPIO.OUT
statements like so:
GPIO.setup(18,GPIO.OUT)
time.sleep(1)
GPIO.setup(23,GPIO.OUT)
time.sleep(1)
GPIO.setup(24,GPIO.OUT)
Upvotes: 5