Added ability to set same color on multiple pixels
Added 4th, optional argument, nPixels, to setRGB() and setHSV().
This commit is contained in:
parent
738dce3ad3
commit
d5b27d6e14
|
|
@ -12,30 +12,31 @@ Pixel::Pixel(int pin, float high0, float low0, float high1, float low1, float lo
|
||||||
LR=lowReset*80;
|
LR=lowReset*80;
|
||||||
|
|
||||||
rf=new RFControl(pin,false); // set clock to 1/80 usec
|
rf=new RFControl(pin,false); // set clock to 1/80 usec
|
||||||
setRGB(0,0,0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
||||||
void Pixel::setRGB(uint8_t r, uint8_t g, uint8_t b){
|
void Pixel::setRGB(uint8_t r, uint8_t g, uint8_t b, int nPixels){
|
||||||
|
|
||||||
if(!*rf)
|
if(!*rf)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
rf->clear();
|
rf->clear();
|
||||||
loadColor(g);
|
for(int i=0;i<nPixels;i++){
|
||||||
loadColor(r);
|
loadColor(g);
|
||||||
loadColor(b);
|
loadColor(r);
|
||||||
|
loadColor(b);
|
||||||
|
}
|
||||||
rf->phase(LR,0); // end-marker delay/reset
|
rf->phase(LR,0); // end-marker delay/reset
|
||||||
rf->start();
|
rf->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
||||||
void Pixel::setHSV(float h, float s, float v){
|
void Pixel::setHSV(float h, float s, float v, int nPixels){
|
||||||
float r,g,b;
|
float r,g,b;
|
||||||
LedPin::HSVtoRGB(h,s,v,&r,&g,&b);
|
LedPin::HSVtoRGB(h,s,v,&r,&g,&b);
|
||||||
setRGB(r*255,g*255,b*255);
|
setRGB(r*255,g*255,b*255,nPixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,9 @@ class Pixel {
|
||||||
Pixel(int pin, float high0, float low0, float high1, float low1, float lowReset); // creates addressable single-wire RGB LED on pin (such as the SK68 or WS28); parameters are in MICROSECONDS!
|
Pixel(int pin, float high0, float low0, float high1, float low1, float lowReset); // creates addressable single-wire RGB LED on pin (such as the SK68 or WS28); parameters are in MICROSECONDS!
|
||||||
Pixel(int pin) : Pixel(pin, 0.32, 0.88, 0.64, 0.56, 80.0) {}; // default parameters for SK68XXMINI-HS LEDs, though will likely work with many other variations as well
|
Pixel(int pin) : Pixel(pin, 0.32, 0.88, 0.64, 0.56, 80.0) {}; // default parameters for SK68XXMINI-HS LEDs, though will likely work with many other variations as well
|
||||||
|
|
||||||
void setRGB(uint8_t r, uint8_t g, uint8_t b); // sets color to rgb values (0-255)
|
void setRGB(uint8_t r, uint8_t g, uint8_t b, int nPixels=1); // sets color of nPixels to rgb values (0-255)
|
||||||
void setHSV(float h, float s, float v); // sets color to hsv values where h=[0,360], s=[0,1], v=[0,1]
|
void setHSV(float h, float s, float v, int nPixels=1); // sets color of nPixels to hsv values where h=[0,360], s=[0,1], v=[0,1]
|
||||||
int getPin(){return(rf->getPin());} // returns pixel pin if valid, else returns -1
|
int getPin(){return(rf->getPin());} // returns pixel pin if valid, else returns -1
|
||||||
|
|
||||||
operator bool(){ // override boolean operator to return true/false if creation succeeded/failed
|
operator bool(){ // override boolean operator to return true/false if creation succeeded/failed
|
||||||
return(*rf);
|
return(*rf);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include "Pixel.h"
|
#include "Pixel.h"
|
||||||
|
|
||||||
|
Pixel px(23);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
Serial.begin(115200); // start the Serial interface
|
Serial.begin(115200); // start the Serial interface
|
||||||
|
|
@ -10,40 +12,19 @@ void setup() {
|
||||||
|
|
||||||
Serial.println("\n\nHomeSpan Pixel Example\n\n");
|
Serial.println("\n\nHomeSpan Pixel Example\n\n");
|
||||||
|
|
||||||
Pixel px(8);
|
|
||||||
Pixel test7(7);
|
|
||||||
Pixel test6(6);
|
|
||||||
|
|
||||||
Serial.printf("PX on Pin=%d check: %s\n",px.getPin(),px?"OKAY":"BAD");
|
Serial.printf("PX on Pin=%d check: %s\n",px.getPin(),px?"OKAY":"BAD");
|
||||||
Serial.printf("Test 7 on Pin=%d check: %s\n",test7.getPin(),test7?"OKAY":"BAD");
|
|
||||||
Serial.printf("Test 6 on Pin=%d check: %s\n",test6.getPin(),test6?"OKAY":"BAD");
|
|
||||||
|
|
||||||
for(int i=0;i<5;i++){
|
|
||||||
px.setHSV(60,0.9,0.5);
|
|
||||||
delay(1000);
|
|
||||||
px.setHSV(120,0.9,0.5);
|
|
||||||
delay(1000);
|
|
||||||
px.setHSV(240,0.9,0.5);
|
|
||||||
delay(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// while(1){
|
|
||||||
// for(int i=0;i<50;i++){
|
|
||||||
// px.setRGB(i,0,0);
|
|
||||||
// delay(2);
|
|
||||||
// }
|
|
||||||
// for(int i=50;i>=0;i--){
|
|
||||||
// px.setRGB(i,0,0);
|
|
||||||
// delay(2);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
Serial.println("Done!");
|
|
||||||
|
|
||||||
} // end of setup()
|
} // end of setup()
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
|
|
||||||
|
for(int i=0;i<5;i++){
|
||||||
|
px.setHSV(0,1.0,1.0,3);
|
||||||
|
delay(1000);
|
||||||
|
px.setHSV(120,1.0,1.0,3);
|
||||||
|
delay(1000);
|
||||||
|
px.setHSV(240,1.0,1.0,3);
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
|
||||||
} // end of loop()
|
} // end of loop()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue