Merge branch 'master' of https://gitlab.com/tliero/smart-home
This commit is contained in:
@@ -20,31 +20,39 @@ PIN_REMOTE = 26
|
||||
PIN_LED = 11
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(PIN_MOTOR_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(PIN_REMOTE_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(PIN_MOTOR_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
GPIO.setup(PIN_REMOTE_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
GPIO.setup(PIN_MOTOR, GPIO.OUT)
|
||||
GPIO.setup(PIN_REMOTE, GPIO.OUT)
|
||||
GPIO.setup(PIN_LED, GPIO.OUT)
|
||||
|
||||
|
||||
def motor_button(channel):
|
||||
time.sleep(0.01) # el cheapo relay module creates lots of interference, so we check again after a waiting period (see https://electronics.stackexchange.com/a/361793/253533)
|
||||
if channel == 0 or GPIO.input(PIN_MOTOR_BUTTON) == False:
|
||||
logging.info("trigger motor")
|
||||
GPIO.output(PIN_MOTOR, GPIO.LOW)
|
||||
GPIO.output(PIN_LED, GPIO.HIGH)
|
||||
time.sleep(0.4)
|
||||
GPIO.output(PIN_MOTOR, GPIO.HIGH)
|
||||
GPIO.output(PIN_LED, GPIO.LOW)
|
||||
else:
|
||||
logging.info("flare (motor button)")
|
||||
|
||||
def remote_button(channel):
|
||||
logging.info("trigger remote")
|
||||
time.sleep(0.01)
|
||||
if channel == 0 or GPIO.input(PIN_REMOTE_BUTTON) == False:
|
||||
logging.info("trigger remote 0.8")
|
||||
GPIO.output(PIN_REMOTE, GPIO.HIGH)
|
||||
GPIO.output(PIN_LED, GPIO.HIGH)
|
||||
time.sleep(0.4)
|
||||
time.sleep(0.8)
|
||||
GPIO.output(PIN_REMOTE, GPIO.LOW)
|
||||
GPIO.output(PIN_LED, GPIO.LOW)
|
||||
else:
|
||||
logging.info("flare (remote button)")
|
||||
|
||||
GPIO.add_event_detect(PIN_MOTOR_BUTTON, GPIO.RISING, callback=motor_button, bouncetime=250)
|
||||
GPIO.add_event_detect(PIN_REMOTE_BUTTON, GPIO.RISING, callback=remote_button, bouncetime=250)
|
||||
GPIO.add_event_detect(PIN_MOTOR_BUTTON, GPIO.FALLING, callback=motor_button, bouncetime=250)
|
||||
GPIO.add_event_detect(PIN_REMOTE_BUTTON, GPIO.FALLING, callback=remote_button, bouncetime=250)
|
||||
|
||||
GPIO.output(PIN_MOTOR, GPIO.HIGH)
|
||||
GPIO.output(PIN_REMOTE, GPIO.LOW)
|
||||
|
||||
Reference in New Issue
Block a user