Skip to content

Fix NeoPixel brightness bug #72

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 7, 2021
Merged

Fix NeoPixel brightness bug #72

merged 1 commit into from
Jun 7, 2021

Conversation

jfurcean
Copy link
Contributor

@jfurcean jfurcean commented Jun 7, 2021

Fixes a bug that prevents brightness from being updated in some cases. I tested this on the QT Rotary Encoder. The test code provided by @kattni.

import time
import board
import busio
from adafruit_seesaw import seesaw, neopixel, rotaryio, digitalio
try:
    import _pixelbuf
except ImportError:
    import adafruit_pypixelbuf as _pixelbuf

i2c = busio.I2C(board.SCL1, board.SDA1)
seesaw = seesaw.Seesaw(i2c, 0x36)

encoder = rotaryio.IncrementalEncoder(seesaw)
switch = digitalio.DigitalIO(seesaw, 24)

pixel = neopixel.NeoPixel(seesaw, 6, 1)

last_position = -1
color = 0  # start at red

while True:
    position = encoder.position
    if position != last_position:
        print(position)
        print(switch.value)
        if switch.value:
            # change the color
            if position > last_position:  # increase
                color += 1
            else:
                color -= 1
            color = (color + 256) % 256  # wrap around to 0-256
            pixel.fill(_pixelbuf.colorwheel(color))
        else:
            # change the brightness
            if position > last_position:  # increase
                pixel.brightness = min(1.0, pixel.brightness + 0.1)
            else:
                pixel.brightness = max(0, pixel.brightness - 0.1)
    last_position = position

Copy link
Contributor

@kattni kattni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update! I didn't even get a chance to file the issue!

@kattni
Copy link
Contributor

kattni commented Jun 7, 2021

Tested successfully.

@kattni kattni merged commit 5812855 into adafruit:main Jun 7, 2021
evaherrada added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jun 7, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_Seesaw to 1.9.0 from 1.8.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_seesaw#72 from jfurcean/fix-brightness
  > Moved default branch to main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants