Jan-21-2018, 02:50 PM
(This post was last modified: Jan-21-2018, 02:58 PM by sparkz_alot.)
Greetings to the Group
I am a beginner to python so be nice to me.
I am trying to control a GPIO output from a HIGH input and have the output stay HIGH for a specific time. I have written the script and it works sort of.
The problem I'm seeing is, if the input goes LOW and then back to HIGH and back to LOW before the "sleep time" had finished, it does not reset the Output time.
I am using the "sleep time" but I don't think this is the correct way to control the Output timing. As I said I'm very new to programming and if anyone can help me here it would be greatly appreciated. I know the answer is simple but I'm not seeing it.
I have attached the code I have written, below.
I am a beginner to python so be nice to me.
I am trying to control a GPIO output from a HIGH input and have the output stay HIGH for a specific time. I have written the script and it works sort of.
The problem I'm seeing is, if the input goes LOW and then back to HIGH and back to LOW before the "sleep time" had finished, it does not reset the Output time.
I am using the "sleep time" but I don't think this is the correct way to control the Output timing. As I said I'm very new to programming and if anyone can help me here it would be greatly appreciated. I know the answer is simple but I'm not seeing it.
I have attached the code I have written, below.
import RPi.GPIO as GPIO from time import sleep #import time library GPIO.setmode(GPIO.BCM) GPIO.setup(4,GPIO.IN) # set i/p sig to GPIO pin 4 GPIO.setwarnings(False) GPIO.setup(26,GPIO.OUT,initial=GPIO.LOW) #set o/p sig to GPIO pin26, initiallize in low state GPIO.setup(4,GPIO.IN,pull_up_down=GPIO.PUD_DOWN) #set internal pulldown resistor try: while True: if (GPIO.input(4)==1): GPIO.output(26,1) sleep(10) else: GPIO.output(26,0) sleep(.1) finally: GPIO.output(26,False) GPIO.cleanup