I'm planning to make a car robot with RPi. I have a python script named 'abc.py', and I'd like to kill the python program and cleanup GPIOs used in abc.py when a button connected to GPIO is pressed. What should I do?
If the button is connected to a GPIO pin and a GND pin,
button_gpio=<Button GPIO pin here> GPIO.setup(button_gpio, GPIO.IN, pull_up_down = GPIO.PUD_UP) while True: if (GPIO.input(button_gpio) == 0): print(“Button pressed”) GPIO.cleanup() exit()