按下按钮时GPIO 18无法读取

时间:2018-09-05 12:30:08

标签: python raspberry-pi raspberry-pi3

您好,我目前正在使用此功能,但我感到困惑,为什么当我按按钮时BCM 18却什么也不做

import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(27,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

counter = 0
totalPulse = 0

try:
    while True:
        sleep(0.1)

        GPIO.wait_for_edge(27, GPIO.RISING)
        print("Hello 27!", counter)
        totalPulse = counter
        counter+=1

        input_state = GPIO.input(18)
        if input_state == False:
            totalPulse - 1
            print(totalPulse)

0 个答案:

没有答案