found relay control functipn

Signed-off-by: Ebbe Baß <ebbe@ping-mee.de>
master
Ebbe Baß 2022-07-14 01:11:50 +02:00
parent 928e281ef1
commit 264b35ed0b
1 changed files with 4 additions and 21 deletions

25
main.py
View File

@ -13,23 +13,6 @@ except ImportError:
print(ImportError)
exit()
RELAY_PIN_CH_1 = 4
RELAY_PIN_CH_2 = 17
RELAY_PIN_CH_3 = 27
RELAY_PIN_CH_4 = 11
global relay_ch_1
relay_ch_1 = gpiozero.OutputDevice(RELAY_PIN_CH_1, active_high=True, initial_value=False)
# global relay_ch_2
# relay_ch_2 = gpiozero.OutputDevice(RELAY_PIN_CH_2, active_high=True, initial_value=False)
# global relay_ch_3
# relay_ch_3 = gpiozero.OutputDevice(RELAY_PIN_CH_3, active_high=True, initial_value=False)
# global relay_ch_4
# relay_ch_4 = gpiozero.OutputDevice(RELAY_PIN_CH_4, active_high=True, initial_value=False)
def debug_print(message: str):
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
@ -41,15 +24,15 @@ def error_print(message: str):
print('[ERROR]['+current_time+'] '+message)
#relay
def relay_controller(pin: int, status: str):
if status == "ON":
def relay_controller(pin: int, state: str):
if state == True:
relay = gpiozero.OutputDevice(pin, active_high=False, initial_value=False)
relay.on()
elif status == "OFF":
elif state == False:
relay = gpiozero.OutputDevice(pin, active_high=False, initial_value=False)
relay.off()
else:
error_print("Unknown status for relay ("+status+")")
error_print("Unknown state for relay ("+state+")")
#ultrasonic