按钮接线按对角线来接线,一端接gnd,一端接gpio23
root@raspberrypi:/home/pi/gpio# cat button.py
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import time
import signal
import atexit
import os
atexit.register(GPIO.cleanup)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
btn=23
GPIO.setup(btn, GPIO.IN, pull_up_down=GPIO.PUD_UP)
button = GPIO.input(btn)
#print button
i=0
while True:
if GPIO.input(btn) == 0:
i=i+1
#print i
print "the button is pressed"
os.system("raspistill -rot 180 -o "+str(i)+".jpg");
#else:
#print "hi"
GPIO.cleanup()