Hardware Reference
In-Depth Information
GPIO Input and Output (Chapter 12)
#!/usr/bin/env python
# Raspberry Pi GPIO Input/Output example
# Written by Gareth Halfacree for the Raspberry Pi User Guide
import RPi.GPIO as GPIO
GPIO.setup(11, GPIO.OUT)
GPIO.setup(12, GPIO.IN)
GPIO.output(11, False)
while True:
input_value = GPIO.input(12)
if input_value == False:
print “The button has been pressed. Lighting LED.”
GPIO.output(11, True)
while input_value == False:
input_value = GPIO.input(12)
print “The button has been released. Extinguishing LED.”
if input_value == True:
GPIO.output(11, False)
Search WWH ::




Custom Search