2022-07-17 15:07:40 +00:00
|
|
|
import gpiozero
|
2022-07-13 23:50:14 +00:00
|
|
|
import time
|
|
|
|
from datetime import datetime
|
2022-07-17 15:07:40 +00:00
|
|
|
import RPi.GPIO as GPIO
|
2022-07-16 22:53:22 +00:00
|
|
|
|
2022-07-13 23:50:14 +00:00
|
|
|
|
2022-07-17 15:26:16 +00:00
|
|
|
# GPIO.setmode(GPIO.BCM)
|
2022-07-14 08:57:46 +00:00
|
|
|
|
2022-07-17 15:26:16 +00:00
|
|
|
# GPIO.setup(19, GPIO.OUT)
|
|
|
|
# GPIO.output(19, GPIO.HIGH)
|
|
|
|
# time.sleep(1)
|
|
|
|
# GPIO.output(19, GPIO.LOW)
|
|
|
|
# time.sleep(5)
|
|
|
|
# GPIO.cleanup()
|
2022-07-17 15:07:40 +00:00
|
|
|
|
2022-07-17 15:26:16 +00:00
|
|
|
def debug_print(message: str):
|
|
|
|
now = datetime.now()
|
|
|
|
current_time = now.strftime("%H:%M:%S")
|
|
|
|
print('[DEBUG]['+current_time+'] '+message)
|
2022-07-17 14:50:17 +00:00
|
|
|
|
2022-07-17 15:26:16 +00:00
|
|
|
def error_print(message: str):
|
|
|
|
now = datetime.now()
|
|
|
|
current_time = now.strftime("%H:%M:%S")
|
|
|
|
print('[ERROR]['+current_time+'] '+message)
|
2022-07-17 14:50:17 +00:00
|
|
|
|
2022-07-17 15:26:16 +00:00
|
|
|
def relay_controller(pin: int, state: str):
|
|
|
|
if state == "True":
|
|
|
|
relay = gpiozero.OutputDevice(pin, active_high=False, initial_value=False)
|
|
|
|
relay.on()
|
|
|
|
debug_print("Set relay-pin "+str(pin)+" to state True")
|
|
|
|
elif state == "False":
|
|
|
|
relay = gpiozero.OutputDevice(pin, active_high=False, initial_value=False)
|
|
|
|
relay.off()
|
|
|
|
debug_print("Set relay-pin "+str(pin)+" to state False")
|
|
|
|
else:
|
|
|
|
error_print("Unknown state for relay ("+state+")")
|
2022-07-17 14:50:17 +00:00
|
|
|
|
2022-07-17 15:26:16 +00:00
|
|
|
while True:
|
|
|
|
relay_controller(19, "True")
|
|
|
|
time.sleep(2)
|
|
|
|
relay_controller(19, "False")
|
|
|
|
time.sleep(2)
|