TypeError:__gt__ 不支持的类型:'int'、'NoneType' - Circuit Python

问题描述 投票:0回答:1

我采用了旋转编码器的 Adafruit 代码示例([旋转编码器][1]),并对其进行了更改,以便我可以使用 Raspberry Pi Pico 作为 HID 来控制 PC 的音量。

#
# SPDX-License-Identifier: MIT

import rotaryio
import board
from adafruit_hid.keycode import Keycode
from adafruit_hid.consumer_control_code import ConsumerControlCode

encoder = rotaryio.IncrementalEncoder(board.GP12, board.GP13)
last_position = None

while True:
    position = encoder.position
    
    if last_position is None or position != last_position:
        if position > last_position:
            cc.send(ConsumerControlCode.VOLUME_INCREMENT)
            time.sleep(0.01)
            print("Volume up")
        elif position < last_position:
            cc.send(ConsumerControlCode.VOLUME_DECREMENT)
            time.sleep(0.01)
            print("Volume down")
        else:
            print("No change")
            
    last_position = position


Unfortunately I get the above mentioned error. I found a similar error here on stackoverflow but it couldn't solve the problem for me.

[1]: https://docs.circuitpython.org/en/latest/shared-bindings/rotaryio/index.html
raspberry-pi-pico adafruit-circuitpython
1个回答
0
投票

将last_position设置为0解决了问题。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.