From 538745f40f554b8916c26f1cee27db9cc4059f26 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Tue, 8 Jun 2021 10:57:31 -0400 Subject: [PATCH 1/3] Adding rotary QT NeoPixel example. --- examples/seesaw_rotary_neopixel.py | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 examples/seesaw_rotary_neopixel.py diff --git a/examples/seesaw_rotary_neopixel.py b/examples/seesaw_rotary_neopixel.py new file mode 100644 index 0000000..b8790eb --- /dev/null +++ b/examples/seesaw_rotary_neopixel.py @@ -0,0 +1,47 @@ +"""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: + # 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 From 699487217ae9cbbd63564e729c39f3c5eb210539 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Tue, 8 Jun 2021 11:14:02 -0400 Subject: [PATCH 2/3] Add license. --- examples/seesaw_rotary_neopixel.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/seesaw_rotary_neopixel.py b/examples/seesaw_rotary_neopixel.py index b8790eb..eabeda0 100644 --- a/examples/seesaw_rotary_neopixel.py +++ b/examples/seesaw_rotary_neopixel.py @@ -1,3 +1,6 @@ +# 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 From fa15b1ca7cb1b0b26f6366c3924bdb9d5ebe7c3b Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Tue, 8 Jun 2021 11:18:20 -0400 Subject: [PATCH 3/3] Blacken. --- examples/seesaw_rotary_neopixel.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/seesaw_rotary_neopixel.py b/examples/seesaw_rotary_neopixel.py index eabeda0..3d4ecb1 100644 --- a/examples/seesaw_rotary_neopixel.py +++ b/examples/seesaw_rotary_neopixel.py @@ -4,6 +4,7 @@ """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: