Added static HSV and RGB color methods to Pixel() and Dot()

Updated Pixel example to demonstrate use of the static HSV method
This commit is contained in:
Gregg 2022-02-17 18:27:31 -06:00
parent 5e72dcbbea
commit a83d3a7fda
3 changed files with 18 additions and 5 deletions

View File

@ -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<float>(); // range = [0,100]
float v=V.getNewVal<float>(); // 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;i<nPixels;i++)
color[i].HSV(h+i*hueStep*p,s*p,100,v*p); // create spectrum of all hues starting with specified Hue; use current-limiting parameter (4th argument) to control overall brightness, instead of PWM
pixel->set(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
}

View File

@ -116,6 +116,9 @@ class Pixel {
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
};
////////////////////////////////////////////

View File

@ -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)