Simple test for QT Py RP2040 vs QT Py M0¶
This example explicitly checks to see if the board is an RP2040-variant.
examples/ruhrohrotaryio_simpletest.py¶
1# SPDX-FileCopyrightText: Copyright (c) 2023 Tod Kurt
2#
3# SPDX-License-Identifier: Unlicense
4
5import os
6import time
7import board
8
9# works on both QTPY M0 and QTPY RP2040
10
11if os.uname().machine.find("rp2040") > 0: # RP2040
12 from ruhrohrotaryio import IncrementalEncoder
13else:
14 from rotaryio import IncrementalEncoder
15
16encoder = IncrementalEncoder(board.A3, board.A1)
17
18while True:
19 print(encoder.position)
20 time.sleep(0.1)
Simple test for any board¶
This example first tries rotaryio and if that fail tries ruhrohrotaryio.
examples/ruhrohrotaryio_workanywhere.py¶
1# SPDX-FileCopyrightText: Copyright (c) 2023 Tod Kurt
2#
3# SPDX-License-Identifier: Unlicense
4
5import time
6import board
7
8# works on any board
9encoder = None
10try:
11 import rotaryio
12
13 encoder = rotaryio.IncrementalEncoder(board.A3, board.A1)
14except (RuntimeError, ImportError):
15 print("ruhroh")
16 import ruhrohrotaryio as rotaryio
17
18 encoder = rotaryio.IncrementalEncoder(board.A3, board.A1)
19
20while True:
21 print(encoder.position)
22 time.sleep(0.1)