【问题标题】:Reading A Rotary Encoder in pyfirmata在 pyfirmata 中读取旋转编码器
【发布时间】:2022-11-05 00:33:06
【问题描述】:

我正在尝试从带有 pyfirmata 的编码器中获取数据。但我找不到关于这个特定主题的任何内容。如果有人可以帮助我,我将不胜感激。

【问题讨论】:

    标签: python arduino pyfirmata


    【解决方案1】:

    这里

    别针

    时钟-> D8

    DT -> D7

    from pyfirmata import Arduino, util
    import pyfirmata.util
    
    counter = 0
    
    board = Arduino('COM3')
    
    iterator = pyfirmata.util.Iterator(board)
    iterator.start()
    
    board.digital[9].mode = pyfirmata.INPUT
    board.digital[8].mode = pyfirmata.INPUT
    
    aLastState = board.digital[9].read()
    
    while True:
        aState = board.digital[9].read()
        if aState != aLastState:
            if board.digital[8].read() != aState:
                counter +=1
            else:
                counter -= 1
            print(f'Position: {counter}')
        aLastState = aState
    
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多