Added rotary encoder example with debouncer
This commit is contained in:
parent
2ec2951415
commit
32d339c0fa
|
@ -0,0 +1,35 @@
|
||||||
|
# Ref: https://learn.adafruit.com/adafruit-i2c-qt-rotary-encoder/python-circuitpython
|
||||||
|
import board
|
||||||
|
from adafruit_seesaw import seesaw, rotaryio, digitalio
|
||||||
|
import busio
|
||||||
|
from adafruit_debouncer import Button # Also requires adafruit_ticks to be present in /lib/
|
||||||
|
|
||||||
|
SDA = board.GP0
|
||||||
|
SCL = board.GP1
|
||||||
|
i2c = busio.I2C(SCL, SDA)
|
||||||
|
seesaw = seesaw.Seesaw(i2c, 0x36)
|
||||||
|
|
||||||
|
seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
|
||||||
|
pin = digitalio.DigitalIO(seesaw, 24)
|
||||||
|
button = Button(pin)
|
||||||
|
|
||||||
|
encoder = rotaryio.IncrementalEncoder(seesaw)
|
||||||
|
last_position = None
|
||||||
|
|
||||||
|
while True:
|
||||||
|
# Update the debouncer.
|
||||||
|
# Needs to happen very frequently
|
||||||
|
button.update()
|
||||||
|
|
||||||
|
# negate the position to make clockwise rotation positive
|
||||||
|
position = -encoder.position
|
||||||
|
|
||||||
|
if position != last_position:
|
||||||
|
last_position = position
|
||||||
|
print("Position: {}".format(position))
|
||||||
|
|
||||||
|
if button.short_count == 1:
|
||||||
|
print("Button was short pressed once")
|
||||||
|
|
||||||
|
if button.long_press:
|
||||||
|
print("Button was long pressed")
|
Loading…
Reference in New Issue