Skip to content

Update rotary examples #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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