树莓派按钮

按钮接线按对角线来接线,一端接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()

    A+
发布日期:2016年12月25日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: