反向开关事件-Python,Pi

时间:2018-10-05 02:42:17

标签: python

我遇到一种情况,即开关通常处于关闭状态,并且在打开时会触发事件。

我发现以下代码可以正常工作,所以我想我需要以某种方式反转它才能执行所需的操作。显然,该文本将被更改为例如“ Contact open”。

import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library

def button_callback(channel):
    print("Button was pushed!")

GPIO.setwarnings(False) # Ignore warning for now
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set pin 10 to be an input pin and set initial value to be pulled low (off)

GPIO.add_event_detect(10,GPIO.RISING,callback=button_callback) # Setup event on pin 10 rising edge

message = input("Press enter to quit\n\n") # Run until someone presses enter

GPIO.cleanup() # Clean up

0 个答案:

没有答案