Skip to content

Commit

Permalink
Merge pull request #94 from jedgarpark/multi-rotary
Browse files Browse the repository at this point in the history
adding multiple qt rotary example
  • Loading branch information
jedgarpark committed Feb 2, 2022
2 parents c045512 + 3c7cb9a commit d3c51b7
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions examples/seesaw_rotary_multiples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# SPDX-FileCopyrightText: 2021 John Park
# SPDX-License-Identifier: MIT

# I2C rotary encoder multiple test example.
# solder the A0 jumper on the second QT Rotary Encoder board

import board
from adafruit_seesaw import seesaw, rotaryio, digitalio, neopixel

qt_enc1 = seesaw.Seesaw(board.I2C(), addr=0x36)
qt_enc2 = seesaw.Seesaw(board.I2C(), addr=0x37)

qt_enc1.pin_mode(24, qt_enc1.INPUT_PULLUP)
button1 = digitalio.DigitalIO(qt_enc1, 24)
button_held1 = False

qt_enc2.pin_mode(24, qt_enc2.INPUT_PULLUP)
button2 = digitalio.DigitalIO(qt_enc2, 24)
button_held2 = False

encoder1 = rotaryio.IncrementalEncoder(qt_enc1)
last_position1 = None

encoder2 = rotaryio.IncrementalEncoder(qt_enc2)
last_position2 = None

pixel1 = neopixel.NeoPixel(qt_enc1, 6, 1)
pixel1.brightness = 0.2
pixel1.fill(0xFF0000)

pixel2 = neopixel.NeoPixel(qt_enc2, 6, 1)
pixel2.brightness = 0.2
pixel2.fill(0x0000FF)


while True:

# negate the position to make clockwise rotation positive
position1 = -encoder1.position
position2 = -encoder2.position

if position1 != last_position1:
last_position1 = position1
print("Position 1: {}".format(position1))

if not button1.value and not button_held1:
button_held1 = True
pixel1.brightness = 0.5
print("Button 1 pressed")

if button1.value and button_held1:
button_held1 = False
pixel1.brightness = 0.2
print("Button 1 released")

if position2 != last_position2:
last_position2 = position2
print("Position 2: {}".format(position2))

if not button2.value and not button_held2:
button_held2 = True
pixel2.brightness = 0.5
print("Button 2 pressed")

if button2.value and button_held2:
button_held2 = False
pixel2.brightness = 0.2
print("Button 2 released")

0 comments on commit d3c51b7

Please sign in to comment.