File tree Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2017 Dean Miller for Adafruit Industries
2+ #
3+ # SPDX-License-Identifier: MIT
4+
5+ # pylint: disable=missing-docstring,invalid-name,too-many-public-methods
6+
7+
8+ """
9+ `adafruit_seesaw.digitalio`
10+ ====================================================
11+ """
12+
13+ __version__ = "0.0.0-auto.0"
14+ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git"
15+
16+
17+ class IncrementalEncoder :
18+ """IncrementalEncoder determines the relative rotational position based
19+ on two series of pulses."""
20+
21+ def __init__ (self , seesaw , encoder = 0 ):
22+ """Create an IncrementalEncoder object associated with the given
23+ eesaw device."""
24+ self ._seesaw = seesaw
25+ self ._encoder = encoder
26+
27+ @property
28+ def position (self ):
29+ """The current position in terms of pulses. The number of pulses per
30+ rotation is defined by the specific hardware."""
31+ return self ._seesaw .encoder_position (self ._encoder )
32+
33+ @position .setter
34+ def position (self , value ):
35+ self ._seesaw .set_encoder_position (value , self ._encoder )
Original file line number Diff line number Diff line change 44import board
55from adafruit_seesaw .seesaw import Seesaw
66from adafruit_seesaw .digitalio import DigitalIO
7+ from adafruit_seesaw .rotaryio import IncrementalEncoder
78
89i2c_bus = board .I2C ()
910
1011seesaw = Seesaw (i2c_bus , addr = 0x36 )
1112
13+ seesaw_product = (seesaw .get_version () >> 16 ) & 0xFFFF
14+ print ("Found product {}" .format (seesaw_product ))
15+ if seesaw_product != 4991 :
16+ print ("Wrong firmware loaded? Expected 4991" )
17+
1218button = DigitalIO (seesaw , 24 )
1319button_held = False
1420
15- last_position = seesaw .encoder_position ()
21+ encoder = IncrementalEncoder (seesaw )
22+ last_position = None
1623
1724while True :
1825
1926 # read position of the rotary encoder
20- position = seesaw . encoder_position ()
27+ position = encoder . position
2128 if position != last_position :
2229 last_position = position
2330 print ("Position: {}" .format (position ))
You can’t perform that action at this time.
0 commit comments