start.py
1 import RPi.GPIO as GPIO 2 import time 3 import subprocess # Import the subprocess module 4 5 6 7 8 9 GPIO.setmode(GPIO.BCM) 10 11 GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_UP) 12 13 while True: 14 input_state = GPIO.input(15) 15 if input_state == False: 16 print('Button Pressed') 17 subprocess.run(["python","script.py"]) # Run script.py when the sensor is touched 18 19 time.sleep(0.2)