Update Pixel.ino
This commit is contained in:
parent
6f4cea1b4d
commit
3e1c676f90
|
|
@ -34,9 +34,42 @@
|
||||||
#include "HomeSpan.h"
|
#include "HomeSpan.h"
|
||||||
#include "extras/Pixel.h" // include the HomeSpan Pixel class
|
#include "extras/Pixel.h" // include the HomeSpan Pixel class
|
||||||
|
|
||||||
|
CUSTOM_CHAR(Selector, 00000001-0001-0001-0001-46637266EA00, PR+PW+EV, UINT8, 1, 1, 5, false); // create Custom Characteristic to "select" special effects via Eve App
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
struct Pixel_Light : Service::LightBulb { // Addressable RGB Pixel Strand of nPixel Pixels - assume SAME color for every Pixel
|
struct Pixel_Light : Service::LightBulb { // Addressable RGB Pixel
|
||||||
|
|
||||||
|
Characteristic::On power{0,true};
|
||||||
|
Characteristic::Hue H{0,true};
|
||||||
|
Characteristic::Saturation S{0,true};
|
||||||
|
Characteristic::Brightness V{100,true};
|
||||||
|
Pixel *pixel;
|
||||||
|
|
||||||
|
Pixel_Light(int pin) : Service::LightBulb(){
|
||||||
|
|
||||||
|
V.setRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1%
|
||||||
|
pixel=new Pixel(pin); // creates pixel LED on specified pin using default timing parameters suitable for most SK68xx LEDs
|
||||||
|
update(); // manually call update() to set pixel with restored initial values
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean update() override {
|
||||||
|
|
||||||
|
int p=power.getNewVal();
|
||||||
|
|
||||||
|
float h=H.getNewVal<float>(); // range = [0,360]
|
||||||
|
float s=S.getNewVal<float>(); // range = [0,100]
|
||||||
|
float v=V.getNewVal<float>(); // range = [0,100]
|
||||||
|
|
||||||
|
pixel->setHSV(h*p, s*p, v*p); // sets pixel to HSV colors
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
|
|
||||||
|
struct Pixel_Strand : Service::LightBulb { // Addressable RGB Pixel Strand of nPixel Pixels - allows for special effects controlled by custom characreristic
|
||||||
|
|
||||||
Characteristic::On power{0,true};
|
Characteristic::On power{0,true};
|
||||||
Characteristic::Hue H{0,true};
|
Characteristic::Hue H{0,true};
|
||||||
|
|
@ -45,7 +78,7 @@ struct Pixel_Light : Service::LightBulb { // Addressable RGB Pixel Strand o
|
||||||
Pixel *pixel;
|
Pixel *pixel;
|
||||||
int nPixels; // number of Pixels in Strand (default=1)
|
int nPixels; // number of Pixels in Strand (default=1)
|
||||||
|
|
||||||
Pixel_Light(int pin, int nPixels=1) : Service::LightBulb(){
|
Pixel_Strand(int pin, int nPixels=1) : Service::LightBulb(){
|
||||||
|
|
||||||
V.setRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1%
|
V.setRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1%
|
||||||
pixel=new Pixel(pin); // creates pixel LED on specified pin using default timing parameters suitable for most SK68xx LEDs
|
pixel=new Pixel(pin); // creates pixel LED on specified pin using default timing parameters suitable for most SK68xx LEDs
|
||||||
|
|
@ -73,7 +106,7 @@ void setup() {
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
homeSpan.begin(Category::Lighting,"RGB Pixel");
|
homeSpan.begin(Category::Lighting,"RGB Pixels");
|
||||||
|
|
||||||
new SpanAccessory();
|
new SpanAccessory();
|
||||||
new Service::AccessoryInformation();
|
new Service::AccessoryInformation();
|
||||||
|
|
@ -89,6 +122,23 @@ void setup() {
|
||||||
|
|
||||||
new Pixel_Light(8); // create single Pixel attached to pin 8
|
new Pixel_Light(8); // create single Pixel attached to pin 8
|
||||||
|
|
||||||
|
new SpanAccessory();
|
||||||
|
new Service::AccessoryInformation();
|
||||||
|
new Characteristic::Name("Pixel Strand");
|
||||||
|
new Characteristic::Manufacturer("HomeSpan");
|
||||||
|
new Characteristic::SerialNumber("123-ABC");
|
||||||
|
new Characteristic::Model("8-LED NeoPixel");
|
||||||
|
new Characteristic::FirmwareRevision("1.0");
|
||||||
|
new Characteristic::Identify();
|
||||||
|
|
||||||
|
new Service::HAPProtocolInformation();
|
||||||
|
new Characteristic::Version("1.1.0");
|
||||||
|
|
||||||
|
new Pixel_Strand(7,8); // create single Pixel attached to pin 8
|
||||||
|
|
||||||
|
(new Characteristic::Selector())->setUnit("")->setDescription("Color Effect")->setRange(1,5,1);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
@ -96,3 +146,5 @@ void setup() {
|
||||||
void loop() {
|
void loop() {
|
||||||
homeSpan.poll();
|
homeSpan.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue