Added rotary encoder example

This commit is contained in:
David Thurstenson 2022-10-19 12:36:37 -05:00
parent fc4620cbd0
commit ab000a200f
1 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,33 @@
# Ref: https://learn.adafruit.com/adafruit-i2c-qt-rotary-encoder/python-circuitpython
import board
from adafruit_seesaw import seesaw, rotaryio, digitalio
import busio
SDA = board.GP0
SCL = board.GP1
i2c = busio.I2C(SCL, SDA)
seesaw = seesaw.Seesaw(i2c, 0x36)
seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
button = digitalio.DigitalIO(seesaw, 24)
button_held = False
encoder = rotaryio.IncrementalEncoder(seesaw)
last_position = None
while True:
# negate the position to make clockwise rotation positive
position = -encoder.position
if position != last_position:
last_position = position
print("Position: {}".format(position))
if not button.value and not button_held:
button_held = True
print("Button pressed")
if button.value and button_held:
button_held = False
print("Button released")