123456789101112131415161718192021222324252627282930313233343536 |
- #!/usr/bin/python
- # -*- coding: UTF-8 -*-
- import RPi.GPIO as GPIO
- import time
- #GPIO BOARD mode
- BTN_PIN = 36
- #GPIO BCM mode
- #BTN_PIN = 16
- #统计按键次数
- number=0
- def btnInterrupt(BTN_PIN):
- global number
- print("Button Click:%s"%number)
- number = number + 1
- GPIO.setmode(GPIO.BOARD)
- #GPIO.setmode(GPIO.BCM)
- GPIO.setup(BTN_PIN, GPIO.IN, GPIO.PUD_UP)
- GPIO.add_event_detect(BTN_PIN, GPIO.RISING, btnInterrupt, 400)
- try:
- while True:
- time.sleep(3)
- except KeyboardInterrupt:
- pass
- #GPIO资源清理
- GPIO.remove_event_detect(BTN_PIN)
- GPIO.cleanup()
|