-
Notifications
You must be signed in to change notification settings - Fork 36
add support for different chip detection + quad rotary demo #118
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
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3dab6e6
add support for different chip detection + quad rotary demo
ladyada da9a46c
linting
BlitzCityDIY 2310a9b
tested on m4 & raspi
ladyada aadb8ac
Merge branch 'main' of github.com:ladyada/Adafruit_CircuitPython_seesaw
ladyada 6474230
fix typo and make 'default' use the native pin names going forward
ladyada 79c8738
fix two complaints
ladyada 9b0033c
fix missing if
ladyada 8b20eea
lint && black
BlitzCityDIY File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# SPDX-FileCopyrightText: 2023 ladyada for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
|
||
"""I2C rotary encoder NeoPixel color picker and brightness setting example.""" | ||
import board | ||
from rainbowio import colorwheel | ||
import digitalio | ||
import adafruit_seesaw.seesaw | ||
import adafruit_seesaw.neopixel | ||
import adafruit_seesaw.rotaryio | ||
import adafruit_seesaw.digitalio | ||
|
||
# For use with the STEMMA connector on QT Py RP2040 | ||
# import busio | ||
# i2c = busio.I2C(board.SCL1, board.SDA1) | ||
# seesaw = seesaw.Seesaw(i2c, 0x49) | ||
|
||
i2c = board.I2C() # uses board.SCL and board.SDA | ||
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller | ||
seesaw = adafruit_seesaw.seesaw.Seesaw(i2c, 0x49) | ||
|
||
encoders = [adafruit_seesaw.rotaryio.IncrementalEncoder(seesaw, n) for n in range(4)] | ||
switches = [adafruit_seesaw.digitalio.DigitalIO(seesaw, pin) for pin in (12, 14, 17, 9)] | ||
for switch in switches: | ||
switch.switch_to_input(digitalio.Pull.UP) # input & pullup! | ||
|
||
# four neopixels per 'stick' | ||
pixels = adafruit_seesaw.neopixel.NeoPixel(seesaw, 18, 4) | ||
pixels.brightness = 0.5 | ||
|
||
last_positions = [-1, -1, -1, -1] | ||
colors = [0, 0, 0, 0] # start at red | ||
|
||
while True: | ||
# negate the position to make clockwise rotation positive | ||
positions = [encoder.position for encoder in encoders] | ||
|
||
for n, rotary_pos in enumerate(positions): | ||
if rotary_pos != last_positions[n]: | ||
print(f"Rotary #{n}: {rotary_pos}") | ||
last_positions[n] = rotary_pos | ||
|
||
if switches[n].value: # Change the LED color if switch is not pressed | ||
if rotary_pos > last_positions[n]: # Advance forward through the colorwheel. | ||
colors[n] += 8 | ||
else: | ||
colors[n] -= 8 # Advance backward through the colorwheel. | ||
colors[n] = (colors[n] + 256) % 256 # wrap around to 0-256 | ||
|
||
# if switch is pressed, light up white, otherwise use the stored color | ||
if not switches[n].value: | ||
pixels[n] = 0xFFFFFF | ||
else: | ||
pixels[n] = colorwheel(colors[n]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.