I'm wondering if it's possible to have my momentary button control a relay in Python whilst I'm holding the button down?
Currently, I'm able to control the relay with a small python script, switching it on for a duration of 5 secondes:
relay.py:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)
GPIO.output(4, GPIO.LOW)
time.sleep(5)
GPIO.output(4, GPIO.HIGH)
GPIO.cleanup()
print "Done!"
And able to track when the momentary button is being hold down:
button.py:
import os
from time import sleep
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.IN)
while True:
if (GPIO.input(25) == False):
print "Button being pushed!"
sleep(0.025)
Yet, I'm unable to combine the two. Any help would be really appreciated!