测试小胖
2022-07-12 14:28
采纳率: 50%
浏览 19

树莓派GPIO回调使用方式

树莓派中使用事件回调,提示__callback_RIGHT() takes 1 positional argument but 2 were given
#定义引脚
STOP_LEFT = 16
STOP_RIGHT = 18
#引脚赋能
GPIO.setmode(GPIO.BOARD)
GPIO.add_event_detect(STOP_LEFT, GPIO.FALLING, bouncetime=2)
GPIO.add_event_detect(STOP_RIGHT, GPIO.FALLING, bouncetime=2)
class SlideCtrl():
    def __init__(self):
       GPIO.add_event_callback(STOP_LEFT, self.__callback_LEFT)
       GPIO.add_event_callback(STOP_RIGHT, self.__callback_RIGHT)
    def __callback_LEFT(self):
        if self.direction == LEFT:
            self.current = 0
            self.__stop()

    def __callback_RIGHT(self):
        if self.direction == RIGHT:
            self.current = 3200
            self.__stop()
运行结果及报错内容

当边缘检测触发后 提示回调函数typeError
__callback_RIGHT() takes 1 positional argument but 2 were given

我想要达到的结果

class内使用callback 需要怎么传参呢?

1条回答 默认 最新

相关推荐 更多相似问题