events - rpi4 add_event_detect 事件触发器
问题描述
我试图用add_event_detect()
函数在 RPi4 上实现中断。我的结构如下
输入:gpio20,源信号
输出:gpio21,光触发信号
entertime_stamp = time.time()
''' config '''
INPUT_PIN = 20
OUTPUT_PIN = 21
''' gpio '''
GPIO.setmode(GPIO.BCM)
GPIO.setup(INPUT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # pull_up_down=GPIO.PUD_DOWN
GPIO.setup(OUTPUT_PIN, GPIO.OUT, initial=GPIO.LOW)
''' function for event trigger '''
def Interrupt(channel):
global OUTPUT_PIN
global GPIO
global time_stamp # put in to debounce
time_now = time.time()
if ((time_now - time_stamp) >= 0.3 and GPIO.input(INPUT_PIN)==1):
GPIO.output(OUTPUT_PIN, True)
time.sleep(0.2)
GPIO.output(OUTPUT_PIN, False)
print('Action trigger');
time_stamp = time_now
''' interrupt '''
GPIO.add_event_detect(INPUT_PIN, GPIO.RISING, callback = Interrupt, bouncetime = 200)
''' main '''
try:
while True:
print("input: {0}".format(GPIO.input(INPUT_PIN)))
time.sleep(0.5)
我的规则是在接收到gpio20信号上升时触发gpio21(0到1),所以我将add_event_detect()
规则设置为“GPIO.RISING”。
GPIO.add_event_detect(INPUT_PIN, GPIO.RISING, callback = Interrupt, bouncetime = 200)
但是当接收到gpio20信号下降时它也会触发gpio21(0到1)。如何解决?
解决方案
推荐阅读
- javascript - v-img 的 Vuetify 动态高度
- mysql - 在 MySQL 中更新列中的 WHERE 子句与 - OR LOGICAL 运算符结合使用
- azure-data-explorer - 如何使用先前定义/让 externaldata 执行“in”表达式
- amazon-web-services - 将 180 万的 S3 文件夹从私有更改为公共读取失败,没有详细错误
- laravel - 将 PUT 请求更改为 POST 请求以包括图像更新
- google-cloud-platform - 将文件从项目 A 上的 GCP 计算引擎复制到项目 B 上的存储桶会导致 403 Insufficient Permission
- c# - MVVM 与 UI 元素或替代方法交互的正确位置
- google-apps-script - 在 Gmail iOS 应用中为 Gmail 获取组织 GSuite 插件
- python - 在python中删除多个excel文件的索引列
- azure-active-directory - 基于组成员资格的用户配置范围筛选器