# Import the modules to send commands to the system and access GPIO pins from subprocess import call import RPi.GPIO as gpio keep_powered_pin = 18 # Default pin is 8 # Pin to pull high to keep the Pi Supply giving power gpio.setup(keep_powered_pin, gpio.OUT, initial=gpio.HIGH) # Define a function to keep script running def loop(): raw_input() # Define a function to run when an interrupt is called def shutdown(pin): call('halt', shell=False) gpio.setmode(gpio.BOARD) # Set pin numbering to board numbering gpio.setup(7, gpio.IN) # Set up pin 7 as an input gpio.add_event_detect(7, gpio.RISING, callback=shutdown, bouncetime=200) # Set up an interrupt to look for button presses loop() # Run the loop function to keep script running
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question