From a83d3a7fdab09fafbc3dad48dac240eb50d9b5bc Mon Sep 17 00:00:00 2001 From: Gregg Date: Thu, 17 Feb 2022 18:27:31 -0600 Subject: [PATCH] Added static HSV and RGB color methods to Pixel() and Dot() Updated Pixel example to demonstrate use of the static HSV method --- Other Examples/Pixel/Pixel.ino | 15 ++++++++++----- src/extras/Pixel.h | 7 +++++++ src/extras/extras.ino | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Other Examples/Pixel/Pixel.ino b/Other Examples/Pixel/Pixel.ino index 3d94653..f32643a 100644 --- a/Other Examples/Pixel/Pixel.ino +++ b/Other Examples/Pixel/Pixel.ino @@ -124,9 +124,9 @@ struct NeoPixel_RGBW : Service::LightBulb { // Addressable single-wire RGBW float hue=240-(t-140)/3; // add in a splash of color between blue and green to simulated change of color temperature - Pixel::Color color; + // Pixel::Color color; // if static HSV method is used (below), there is no need to first create a Color object - pixel->set(color.HSV(hue, 100, v*p, v*p),nPixels); // sets all nPixels to the same HSV color + pixel->set(pixel->HSV(hue, 100, v*p, v*p),nPixels); // sets all nPixels to the same HSV color (note use of static method pixel->HSV, instead of defining and setting Pixel::Color) return(true); } @@ -159,9 +159,14 @@ struct DotStar_RGB : Service::LightBulb { // Addressable two-wire RGB LED S float s=S.getNewVal(); // range = [0,100] float v=V.getNewVal(); // range = [0,100] - Dot::Color color; + Dot::Color color[nPixels]; // create an arrary of Colors - pixel->set(color.HSV(h*p, s*p, 100, v*p),nPixels); // sets all nPixels to the same HSV color, but instead of PWM, using current-limiting parameter to control overall brightness + float hueStep=360.0/nPixels; // step size for change in hue from one pixel to the next + + for(int i=0;iset(color,nPixels); // set the colors according to the array return(true); } @@ -224,7 +229,7 @@ void setup() { new Characteristic::FirmwareRevision("1.0"); new Characteristic::Identify(); - new DotStar_RGB(DOTSTAR_DATA_PIN,DOTSTAR_CLOCK_PIN,30); // create 30-LED DotStar RGB Strand with full color control, but use current-limiting feature to create flicker-free dimming + new DotStar_RGB(DOTSTAR_DATA_PIN,DOTSTAR_CLOCK_PIN,30); // create 30-LED DotStar RGB Strand displaying a spectrum of colors and using the current-limiting feature of DotStars to create flicker-free dimming } diff --git a/src/extras/Pixel.h b/src/extras/Pixel.h index dae3290..de320aa 100644 --- a/src/extras/Pixel.h +++ b/src/extras/Pixel.h @@ -115,6 +115,9 @@ class Pixel { Pixel(int pin, boolean isRGBW=false); // creates addressable single-wire RGB (false) or RGBW (true) LED connected to pin (such as the SK68 or WS28) void set(Color *c, int nPixels, boolean multiColor=true); // sets colors of nPixels based on array of Colors c; setting multiColor to false repeats Color in c[0] for all nPixels void set(Color c, int nPixels=1){set(&c,nPixels,false);} // sets color of nPixels to be equal to specific Color c + + static Color RGB(uint8_t r, uint8_t g, uint8_t b, uint8_t w=0){return(Color().RGB(r,g,b,w));} // an alternative method for returning an RGB Color + static Color HSV(float h, float s, float v, double w=0){return(Color().HSV(h,s,v,w));} // an alternative method for returning an HSV Color int getPin(){return(rf->getPin());} // returns pixel pin if valid, else returns -1 void setTiming(float high0, float low0, float high1, float low1, uint32_t lowReset); // changes default timings for bit pulse - note parameters are in MICROSECONDS @@ -215,6 +218,10 @@ class Dot { Dot(uint8_t dataPin, uint8_t clockPin); // creates addressable two-wire RGB LED connected to dataPin and clockPin (such as the DotStar SK9822 or APA102) void set(Color *c, int nPixels, boolean multiColor=true); // sets colors of nPixels based on array of Colors c; setting multiColor to false repeats Color in c[0] for all nPixels void set(Color c, int nPixels=1){set(&c,nPixels,false);} // sets color of nPixels to be equal to specific Color c + + static Color RGB(uint8_t r, uint8_t g, uint8_t b, uint8_t driveLevel=31){return(Color().RGB(r,g,b,driveLevel));} // an alternative method for returning an RGB Color + static Color HSV(float h, float s, float v, double drivePercent=100){return(Color().HSV(h,s,v,drivePercent));} // an alternative method for returning an HSV Color + }; //////////////////////////////////////////// diff --git a/src/extras/extras.ino b/src/extras/extras.ino index 9c9fa83..748deba 100644 --- a/src/extras/extras.ino +++ b/src/extras/extras.ino @@ -105,6 +105,7 @@ struct Effect3 { Pixel px1(8); // NeoPixel RGB Pixel px2(9,true); // NeoPixel RGBW Dot dot(2,3); // DotStar + Pixel neo(0); #elif defined(CONFIG_IDF_TARGET_ESP32)