import RPi.GPIO as GPIO import logging import time from threading import Thread logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s - %(message)s') PIN_MOTOR_BUTTON = 23 PIN_REMOTE_BUTTON = 24 PIN_MOTOR = 21 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, GPIO.OUT) GPIO.setup(PIN_REMOTE, GPIO.OUT) GPIO.setup(PIN_LED, GPIO.OUT) def check_motor_button(channel): logging.info("Motor pressed") GPIO.output(PIN_MOTOR, GPIO.LOW) GPIO.output(PIN_LED, GPIO.HIGH) time.sleep(0.8) GPIO.output(PIN_MOTOR, GPIO.HIGH) GPIO.output(PIN_LED, GPIO.LOW) time.sleep(1) def check_remote_button(channel): logging.info("Remote pressed") GPIO.output(PIN_REMOTE, GPIO.HIGH) GPIO.output(PIN_LED, GPIO.HIGH) time.sleep(0.8) GPIO.output(PIN_REMOTE, GPIO.LOW) GPIO.output(PIN_LED, GPIO.LOW) time.sleep(1) GPIO.add_event_detect(PIN_MOTOR_BUTTON, GPIO.FALLING, callback=check_motor_button, bouncetime=200) GPIO.add_event_detect(PIN_REMOTE_BUTTON, GPIO.FALLING, callback=check_remote_button, bouncetime=200) try: GPIO.output(PIN_MOTOR, GPIO.HIGH) GPIO.output(PIN_REMOTE, GPIO.LOW) GPIO.output(PIN_LED, GPIO.LOW) while True: time.sleep(0.01) except KeyboardInterrupt: logging.info('Shutdown') finally: logging.info('Reset GPIO configuration and close') GPIO.cleanup()