diff --git a/src/extras/Pixel.cpp b/src/extras/Pixel.cpp index a2cca3c..1d4c634 100644 --- a/src/extras/Pixel.cpp +++ b/src/extras/Pixel.cpp @@ -3,31 +3,36 @@ /////////////////// -sk68xx::sk68xx(int pin){ - rf=new RFControl(pin,false); - setRGB(0,0,0); +Pixel::Pixel(int pin, float high0, float low0, float high1, float low1, float lowReset){ + + H0=high0*80; // high0, low0, etc. are all in microseconds and must be multiplied by 80 to match 80MHz RFControl clock + L0=low0*80; + H1=high1*80; + L1=low1*80; + LR=lowReset*80; + + rf=new RFControl(pin,false); // set clock to 1/80 usec + setRGB(0,255,0); } /////////////////// -void sk68xx::setRGB(uint8_t r, uint8_t g, uint8_t b){ +void Pixel::setRGB(uint8_t r, uint8_t g, uint8_t b){ if(!*rf) return; - - Serial.printf("%d %d %d\n",r,g,b); rf->clear(); loadColor(g); loadColor(r); loadColor(b); - rf->phase(6400,0); // add 80 usec end-marker delay + rf->phase(LR,0); // end-marker delay/reset rf->start(); } /////////////////// -void sk68xx::setHSV(float h, float s, float v){ +void Pixel::setHSV(float h, float s, float v){ float r,g,b; LedPin::HSVtoRGB(h,s,v,&r,&g,&b); setRGB(r*255,g*255,b*255); @@ -35,12 +40,12 @@ void sk68xx::setHSV(float h, float s, float v){ /////////////////// -void sk68xx::loadColor(uint8_t c){ +void Pixel::loadColor(uint8_t c){ for(int i=7;i>=0;i--){ if((c>>i)&1) - rf->add(51,45); + rf->add(H1,L1); // 1-bit else - rf->add(26,70); + rf->add(H0,L0); // 0-bit } } diff --git a/src/extras/Pixel.h b/src/extras/Pixel.h index 35002d9..d109b02 100644 --- a/src/extras/Pixel.h +++ b/src/extras/Pixel.h @@ -8,17 +8,22 @@ #include "RFControl.h" #include "PwmPin.h" -class sk68xx { +class Pixel { private: - int pin=-1; + uint32_t H0, L0; // High and Low times for a zero-pulse (in units of 1/80 microseconds) + uint32_t H1, L1; // High and Low times for a one-pulse (in units of 1/80 microseconds) + uint32_t LR; // Low time for a reset/end-of-data (in units of 1/80 microseconds) + RFControl *rf; void loadColor(uint8_t c); public: - sk68xx(int pin); // creates addressable SK68XX RGB LED on pin + 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 some SK68XX chips + void setRGB(uint8_t r, uint8_t g, uint8_t b); // sets color 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] - int getPin(){return(rf->getPin());} // returns pin number + 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 return(*rf); diff --git a/src/extras/extras.ino b/src/extras/extras.ino index d62d1b2..a7b1d1a 100644 --- a/src/extras/extras.ino +++ b/src/extras/extras.ino @@ -10,15 +10,15 @@ void setup() { Serial.println("\n\nHomeSpan Pixel Example\n\n"); - sk68xx px(8); - sk68xx test7(7); - sk68xx test6(6); + 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("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"); -while(1){ +for(int i=0;i<5;i++){ px.setHSV(60,0.9,0.5); delay(1000); px.setHSV(120,0.9,0.5); @@ -27,18 +27,18 @@ while(1){ delay(1000); } - while(1); - 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); - } - } + +// 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!");