-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,52 @@ | ||
"""RGB LED strip as a full color light.""" | ||
|
||
import circuitmatter as cm | ||
from circuitmatter.device_types.lighting import extended_color | ||
|
||
import board | ||
import neopixel | ||
|
||
|
||
class RGBPixel(extended_color.ExtendedColorLight): | ||
def __init__(self, name, pixels): | ||
super().__init__(name) | ||
self._pixels = pixels | ||
self._brightness = 0.1 | ||
|
||
@property | ||
def color_rgb(self): | ||
return self._color | ||
|
||
@color_rgb.setter | ||
def color_rgb(self, value): | ||
self._pixels.fill(value) | ||
print(f"new color 0x{value:06x}") | ||
|
||
@property | ||
def brightness(self): | ||
return self._brightness | ||
|
||
@brightness.setter | ||
def brightness(self, value): | ||
self._brightness = value | ||
self._pixels.brightness = value | ||
print(f"new brightness {value}") | ||
|
||
def on(self): | ||
self._pixels.brightness = self._brightness | ||
print("on!") | ||
|
||
def off(self): | ||
self._pixels.brightness = 0 | ||
print("off!") | ||
|
||
|
||
matter = cm.CircuitMatter() | ||
# This is a 8mm NeoPixel breadboard LED. (https://www.adafruit.com/product/1734) | ||
# Any pixelbuf compatible strip should work. The RGBPixel class will control the | ||
# entire strip of pixels. | ||
np = neopixel.NeoPixel(board.D12, 1, pixel_order="RGB") | ||
led = RGBPixel("led1", np) | ||
matter.add_device(led) | ||
while True: | ||
matter.process_packets() |