|
1 | 1 | # SPDX-FileCopyrightText: 2021 John Furcean |
2 | 2 | # SPDX-License-Identifier: MIT |
3 | 3 |
|
| 4 | +"""I2C rotary encoder simple test example.""" |
| 5 | + |
4 | 6 | import board |
5 | | -from adafruit_seesaw.seesaw import Seesaw |
6 | | -from adafruit_seesaw.digitalio import DigitalIO |
7 | | -from adafruit_seesaw.rotaryio import IncrementalEncoder |
| 7 | +from adafruit_seesaw import seesaw, rotaryio, digitalio |
8 | 8 |
|
9 | | -i2c_bus = board.I2C() |
| 9 | +# For use with the STEMMA connector on QT Py RP2040 |
| 10 | +# import busio |
| 11 | +# i2c = busio.I2C(board.SCL1, board.SDA1) |
| 12 | +# seesaw = seesaw.Seesaw(i2c, 0x36) |
10 | 13 |
|
11 | | -seesaw = Seesaw(i2c_bus, addr=0x36) |
| 14 | +seesaw = seesaw.Seesaw(board.I2C(), addr=0x36) |
12 | 15 |
|
13 | 16 | seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF |
14 | 17 | print("Found product {}".format(seesaw_product)) |
15 | 18 | if seesaw_product != 4991: |
16 | 19 | print("Wrong firmware loaded? Expected 4991") |
17 | 20 |
|
18 | | -button = DigitalIO(seesaw, 24) |
| 21 | +seesaw.pin_mode(24, seesaw.INPUT_PULLUP) |
| 22 | +button = digitalio.DigitalIO(seesaw, 24) |
19 | 23 | button_held = False |
20 | 24 |
|
21 | | -encoder = IncrementalEncoder(seesaw) |
| 25 | +encoder = rotaryio.IncrementalEncoder(seesaw) |
22 | 26 | last_position = None |
23 | 27 |
|
24 | 28 | while True: |
25 | 29 |
|
26 | | - # read position of the rotary encoder |
27 | | - position = encoder.position |
| 30 | + # negate the position to make clockwise rotation positive |
| 31 | + position = -encoder.position |
| 32 | + |
28 | 33 | if position != last_position: |
29 | 34 | last_position = position |
30 | 35 | print("Position: {}".format(position)) |
|
0 commit comments