-
Notifications
You must be signed in to change notification settings - Fork 36
Adding rotary QT NeoPixel example. #73
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
|
||
"""I2C rotary encoder NeoPixel color picker and brightness setting example.""" | ||
import board | ||
from adafruit_seesaw import seesaw, neopixel, rotaryio, digitalio | ||
|
||
try: | ||
import _pixelbuf | ||
except ImportError: | ||
import adafruit_pypixelbuf as _pixelbuf | ||
|
||
# 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.I2C(), 0x36) | ||
|
||
encoder = rotaryio.IncrementalEncoder(seesaw) | ||
switch = digitalio.DigitalIO(seesaw, 24) | ||
|
||
pixel = neopixel.NeoPixel(seesaw, 6, 1) | ||
pixel.brightness = 0.5 | ||
|
||
last_position = -1 | ||
color = 0 # start at red | ||
|
||
while True: | ||
position = encoder.position | ||
|
||
if position != last_position: | ||
print(position) | ||
|
||
if switch.value: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you rotate the encoder, and then wait a bit before you press the switch I don't believe this code executes. Is that the intended behavior or should this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code executes when I try to replicate what you're suggesting. I'm not sure if I'm simply not doing it in the manner you're suggesting or if the code is fine. I'm going to merge this, we can continue the discussion if you have suggestions and I can make changes if needed in another PR. |
||
# Change the LED color. | ||
if position > last_position: # Advance forward through the colorwheel. | ||
color += 1 | ||
else: | ||
color -= 1 # Advance backward through the colorwheel. | ||
color = (color + 256) % 256 # wrap around to 0-256 | ||
pixel.fill(_pixelbuf.colorwheel(color)) | ||
|
||
else: # If the button is pressed... | ||
# ...change the brightness. | ||
if position > last_position: # Increase the brightness. | ||
pixel.brightness = min(1.0, pixel.brightness + 0.1) | ||
else: # Decrease the brightness. | ||
pixel.brightness = max(0, pixel.brightness - 0.1) | ||
|
||
last_position = position |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is busio the thing to import here? This is actually a point I'm trying to get a better handle on--when and when not to import busio
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
busio
only need to be imported if you have to specify individual I2C pins or I2C pins other than SCL and SDA. Otherwise, useboard.I2C()
which is basically an object representingboard.SCL, board.SDA
. In the case of the QT Py RP2040 STEMMA connector, it's SDA1 and SCL1, so it would needbusio
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that clears it up, I was afraid I needed to worry about clock timing issues on boards and I just didn't know how to begin knowing when and when not to use it.
Thank you for the explanation!