parent
5526eef647
commit
1a7cc4bff7
67
test.py
67
test.py
|
@ -1,41 +1,42 @@
|
||||||
|
import gpiozero
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
# import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
|
|
||||||
# GPIO.setmode(GPIO.BCM)
|
|
||||||
|
|
||||||
# GPIO.setup(17, GPIO.OUT)
|
GPIO.setmode(GPIO.BCM)
|
||||||
# GPIO.output(17, GPIO.HIGH)
|
|
||||||
# time.sleep(1)
|
|
||||||
# GPIO.output(17, GPIO.LOW)
|
|
||||||
# time.sleep(5)
|
|
||||||
# GPIO.cleanup()
|
|
||||||
|
|
||||||
import gpiozero
|
GPIO.setup(17, GPIO.OUT)
|
||||||
def debug_print(message: str):
|
GPIO.output(17, GPIO.HIGH)
|
||||||
now = datetime.now()
|
time.sleep(1)
|
||||||
current_time = now.strftime("%H:%M:%S")
|
GPIO.output(17, GPIO.LOW)
|
||||||
print('[DEBUG]['+current_time+'] '+message)
|
time.sleep(5)
|
||||||
|
GPIO.cleanup()
|
||||||
|
|
||||||
def error_print(message: str):
|
# def debug_print(message: str):
|
||||||
now = datetime.now()
|
# now = datetime.now()
|
||||||
current_time = now.strftime("%H:%M:%S")
|
# current_time = now.strftime("%H:%M:%S")
|
||||||
print('[ERROR]['+current_time+'] '+message)
|
# print('[DEBUG]['+current_time+'] '+message)
|
||||||
|
|
||||||
def relay_controller(pin: int, state: str):
|
# def error_print(message: str):
|
||||||
if state == "True":
|
# now = datetime.now()
|
||||||
relay = gpiozero.OutputDevice(pin, active_high=False, initial_value=False)
|
# current_time = now.strftime("%H:%M:%S")
|
||||||
relay.on()
|
# print('[ERROR]['+current_time+'] '+message)
|
||||||
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+")")
|
|
||||||
|
|
||||||
while True:
|
# def relay_controller(pin: int, state: str):
|
||||||
relay_controller(7, "True")
|
# if state == "True":
|
||||||
time.sleep(2)
|
# relay = gpiozero.OutputDevice(pin, active_high=False, initial_value=False)
|
||||||
relay_controller(7, "False")
|
# relay.on()
|
||||||
time.sleep(2)
|
# 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+")")
|
||||||
|
|
||||||
|
# while True:
|
||||||
|
# relay_controller(7, "True")
|
||||||
|
# time.sleep(2)
|
||||||
|
# relay_controller(7, "False")
|
||||||
|
# time.sleep(2)
|
Loading…
Reference in New Issue