#Thanks for the offer of help Neradoc I
1 messages · Page 1 of 1 (latest)
# SPDX-FileCopyrightText: 2021 John Furcean
# SPDX-License-Identifier: MIT
"""I2C rotary encoder simple test example."""
import board
import supervisor
import time
from adafruit_seesaw import seesaw, rotaryio, digitalio
# 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.Seesaw(board.STEMMA_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")
seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
button = digitalio.DigitalIO(seesaw, 24)
button_held = False
encoder = rotaryio.IncrementalEncoder(seesaw)
position = 0
last_position = 0
pulse_count = 0
def send_pulse_count(pulse_count):
print('%d pulses sent!' % pulse_count)
while True:
# negate the position to make clockwise rotation positive
position = -encoder.position
if position != last_position:
pulse_count += (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")
send_pulse_count()
pulse_count = 0
the code itself. I realized the issue was that I was initializing last_position as None, rather than 0.
(you can change the quotes to triple backticks for the multiple quotes)
"""
some multiline python
"""
ah cool, good to know @ashen bloom . should I thread code blocks so they don't clutter up the chat?
backticks, the """ are part of the python I put inside 😉