pico8enc -- 树莓派PICO驱动 8 个旋转编码器

树莓派 PICO 和 RP2040 相关应用讨论
回复
头像
shaoziyang
帖子: 3917
注册时间: 2019年 10月 21日 13:48

pico8enc -- 树莓派PICO驱动 8 个旋转编码器

#1

帖子 shaoziyang »

无需额外硬件,就可以直接驱动8个旋转编码器。

图片

代码: 全选

encoder_pins = ( (board.GP12, board.GP13, board.GP16),  # pin A, pin B, pin for switch
                 (board.GP10, board.GP11, board.GP17),
                 (board.GP8, board.GP9, board.GP18),
                 (board.GP6, board.GP7, board.GP19),
                 # ...
                 )
encoders = []
encoder_buttons = []
for pins in encoder_pins:
    pin_A, pin_B, pin_switch = pins
    encoder = rotaryio.IncrementalEncoder( pin_A, pin_B )
    button = DigitalInOut(pin_switch)
    button.pull = Pull.UP
    encoders.append(encoder)
    encoder_buttons.append(button)

while True:
    for i in range(len(encoders)):
      position = encoders[i].position
      button_press = encoder_buttons[i].value
https://github.com/todbot/pico8enc
 

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章