Skip to content

Commit

Permalink
Merge pull request #75 from jfurcean/negate-rotation
Browse files Browse the repository at this point in the history
Update rotary examples
  • Loading branch information
ladyada committed Jun 11, 2021
2 parents 9489deb + 33d1148 commit 4ab8a0f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
5 changes: 4 additions & 1 deletion examples/seesaw_rotary_neopixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
seesaw = seesaw.Seesaw(board.I2C(), 0x36)

encoder = rotaryio.IncrementalEncoder(seesaw)
seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
switch = digitalio.DigitalIO(seesaw, 24)

pixel = neopixel.NeoPixel(seesaw, 6, 1)
Expand All @@ -27,7 +28,9 @@
color = 0 # start at red

while True:
position = encoder.position

# negate the position to make clockwise rotation positive
position = -encoder.position

if position != last_position:
print(position)
Expand Down
23 changes: 14 additions & 9 deletions examples/seesaw_rotary_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
# SPDX-FileCopyrightText: 2021 John Furcean
# SPDX-License-Identifier: MIT

"""I2C rotary encoder simple test example."""

import board
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.digitalio import DigitalIO
from adafruit_seesaw.rotaryio import IncrementalEncoder
from adafruit_seesaw import seesaw, rotaryio, digitalio

i2c_bus = board.I2C()
# For use with the STEMMA connector on QT Py RP2040
# import busio
# i2c = busio.I2C(board.SCL1, board.SDA1)
# seesaw = seesaw.Seesaw(i2c, 0x36)

seesaw = Seesaw(i2c_bus, addr=0x36)
seesaw = seesaw.Seesaw(board.I2C(), addr=0x36)

seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF
print("Found product {}".format(seesaw_product))
if seesaw_product != 4991:
print("Wrong firmware loaded? Expected 4991")

button = DigitalIO(seesaw, 24)
seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
button = digitalio.DigitalIO(seesaw, 24)
button_held = False

encoder = IncrementalEncoder(seesaw)
encoder = rotaryio.IncrementalEncoder(seesaw)
last_position = None

while True:

# read position of the rotary encoder
position = encoder.position
# negate the position to make clockwise rotation positive
position = -encoder.position

if position != last_position:
last_position = position
print("Position: {}".format(position))
Expand Down

0 comments on commit 4ab8a0f

Please sign in to comment.