This commit is contained in:
2020-08-26 21:23:15 +02:00
+24 -16
View File
@@ -20,31 +20,39 @@ PIN_REMOTE = 26
PIN_LED = 11 PIN_LED = 11
GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BCM)
GPIO.setup(PIN_MOTOR_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_DOWN) GPIO.setup(PIN_REMOTE_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(PIN_MOTOR, GPIO.OUT) GPIO.setup(PIN_MOTOR, GPIO.OUT)
GPIO.setup(PIN_REMOTE, GPIO.OUT) GPIO.setup(PIN_REMOTE, GPIO.OUT)
GPIO.setup(PIN_LED, GPIO.OUT) GPIO.setup(PIN_LED, GPIO.OUT)
def motor_button(channel): def motor_button(channel):
logging.info("trigger motor") 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)
GPIO.output(PIN_MOTOR, GPIO.LOW) if channel == 0 or GPIO.input(PIN_MOTOR_BUTTON) == False:
GPIO.output(PIN_LED, GPIO.HIGH) logging.info("trigger motor")
time.sleep(0.4) GPIO.output(PIN_MOTOR, GPIO.LOW)
GPIO.output(PIN_MOTOR, GPIO.HIGH) GPIO.output(PIN_LED, GPIO.HIGH)
GPIO.output(PIN_LED, GPIO.LOW) 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): def remote_button(channel):
logging.info("trigger remote") time.sleep(0.01)
GPIO.output(PIN_REMOTE, GPIO.HIGH) if channel == 0 or GPIO.input(PIN_REMOTE_BUTTON) == False:
GPIO.output(PIN_LED, GPIO.HIGH) logging.info("trigger remote 0.8")
time.sleep(0.4) GPIO.output(PIN_REMOTE, GPIO.HIGH)
GPIO.output(PIN_REMOTE, GPIO.LOW) GPIO.output(PIN_LED, GPIO.HIGH)
GPIO.output(PIN_LED, GPIO.LOW) 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_MOTOR_BUTTON, GPIO.FALLING, callback=motor_button, bouncetime=250)
GPIO.add_event_detect(PIN_REMOTE_BUTTON, GPIO.RISING, callback=remote_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_MOTOR, GPIO.HIGH)
GPIO.output(PIN_REMOTE, GPIO.LOW) GPIO.output(PIN_REMOTE, GPIO.LOW)