0

I'm making a controller for my jacuzzi with a raspberry pi. I have the code below, but whenIi push a button the script sleeps. I want it to keep running (check if other buttons are pressed) but want when button1 is pressed the relays opens for xx time.

Does anybody know how to?

import  RPi.GPIO as GPIO
import time


GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.IN,pull_up_down=GPIO.PUD_UP)#Button1
GPIO.setup(26, GPIO.IN,pull_up_down=GPIO.PUD_UP)#Button2
GPIO.setup(1, GPIO.OUT) #motor relais

GPIO.setup(6, GPIO.IN,pull_up_down=GPIO.PUD_UP)#Buffertanksensor laag
GPIO.setup(5, GPIO.IN,pull_up_down=GPIO.PUD_UP)#Buffertanksensor hoog
GPIO.setup(25, GPIO.OUT) #3-wegklep relais
GPIO.setup(7, GPIO.OUT) #Buffertank full LED

#Button press for on/off  jet motor
while True:
    Button1 = GPIO.input(21)
    if (Button1 == False):
        print("Button press ")
        GPIO.output(1, 0)
        time.sleep(5)
        GPIO.output(1, 1)

    Button2 = GPIO.input(26)
    if (Button2 == False):
        print("Button press 2 ")
        GPIO.output(1, 0)
        time.sleep(20)
        GPIO.output(1, 1)

#Buffertank

    Sensor1 = GPIO.input(6)
    if (Sensor1 == False):
        print("Sensor laag actief")
        GPIO.output(25, 1)
        time.sleep(10)
        GPIO.output(25, 0)

    Sensor2 = GPIO.input(5)
    if (Sensor2 == False):
        print("Sensor hoog actief")
        GPIO.output(7, 0)
time.sleep(0.3)
perfect5th
  • 1,992
  • 1
  • 17
  • 18
Ruben
  • 1
  • 2

0 Answers0