└── footboard.py /footboard.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | 4 | # Initialize GPIO pins 5 | LOCK_PIN = 17 # Example GPIO pin for locking mechanism 6 | SENSOR_PIN = 18 # Example GPIO pin for sensor 7 | 8 | GPIO.setmode(GPIO.BCM) 9 | GPIO.setup(LOCK_PIN, GPIO.OUT) 10 | GPIO.setup(SENSOR_PIN, GPIO.IN) 11 | 12 | # Function to lock the footboard drive engine 13 | def lock_engine(): 14 | GPIO.output(LOCK_PIN, GPIO.HIGH) 15 | print("Engine locked") 16 | 17 | # Function to unlock the footboard drive engine 18 | def unlock_engine(): 19 | GPIO.output(LOCK_PIN, GPIO.LOW) 20 | print("Engine unlocked") 21 | 22 | # Main function to monitor sensor and lock/unlock engine accordingly 23 | def main(): 24 | while True: 25 | if GPIO.input(SENSOR_PIN) == GPIO.HIGH: 26 | lock_engine() 27 | else: 28 | unlock_engine() 29 | time.sleep(0.5) # Check sensor every 0.5 seconds 30 | 31 | if __name__ == "__main__": 32 | try: 33 | main() 34 | except KeyboardInterrupt: 35 | GPIO.cleanup() 36 | --------------------------------------------------------------------------------