_button.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:aiyprojects-raspbian 作者: google 项目源码 文件源码
def __init__(self,
                 channel,
                 polarity=GPIO.FALLING,
                 pull_up_down=GPIO.PUD_UP,
                 debounce_time=0.08):
        """A simple GPIO-based button driver.

        This driver supports a simple GPIO-based button. It works by detecting
        edges on the given GPIO channel. Debouncing is automatic.

        Args:
          channel: the GPIO pin number to use (BCM mode)
          polarity: the GPIO polarity to detect; either GPIO.FALLING or
            GPIO.RISING.
          pull_up_down: whether the port should be pulled up or down; defaults to
            GPIO.PUD_UP.
          debounce_time: the time used in debouncing the button in seconds.
        """

        if polarity not in [GPIO.FALLING, GPIO.RISING]:
            raise ValueError(
                'polarity must be one of: GPIO.FALLING or GPIO.RISING')

        self.channel = int(channel)
        self.polarity = polarity
        self.expected_value = polarity == GPIO.RISING
        self.debounce_time = debounce_time

        GPIO.setmode(GPIO.BCM)
        GPIO.setup(channel, GPIO.IN, pull_up_down=pull_up_down)

        self.callback = None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号