From 264b35ed0b4990ae97d350f0e8b121c9f0b68815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Thu, 14 Jul 2022 01:11:50 +0200 Subject: [PATCH] found relay control functipn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- main.py | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/main.py b/main.py index 618831a..ed50bc6 100644 --- a/main.py +++ b/main.py @@ -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