renamed sk68xx class to Pixel and made it generic
Constructor now allows you to specify high/low timings for 1-bit and 0-bit, as well as timing for reset delay. Default parameters are included if none are specified.
This commit is contained in:
parent
3b6bc13b1c
commit
368a06301a
|
|
@ -3,31 +3,36 @@
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
||||||
sk68xx::sk68xx(int pin){
|
Pixel::Pixel(int pin, float high0, float low0, float high1, float low1, float lowReset){
|
||||||
rf=new RFControl(pin,false);
|
|
||||||
setRGB(0,0,0);
|
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)
|
if(!*rf)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Serial.printf("%d %d %d\n",r,g,b);
|
|
||||||
|
|
||||||
rf->clear();
|
rf->clear();
|
||||||
loadColor(g);
|
loadColor(g);
|
||||||
loadColor(r);
|
loadColor(r);
|
||||||
loadColor(b);
|
loadColor(b);
|
||||||
rf->phase(6400,0); // add 80 usec end-marker delay
|
rf->phase(LR,0); // end-marker delay/reset
|
||||||
rf->start();
|
rf->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
||||||
void sk68xx::setHSV(float h, float s, float v){
|
void Pixel::setHSV(float h, float s, float v){
|
||||||
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);
|
||||||
|
|
@ -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--){
|
for(int i=7;i>=0;i--){
|
||||||
if((c>>i)&1)
|
if((c>>i)&1)
|
||||||
rf->add(51,45);
|
rf->add(H1,L1); // 1-bit
|
||||||
else
|
else
|
||||||
rf->add(26,70);
|
rf->add(H0,L0); // 0-bit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,22 @@
|
||||||
#include "RFControl.h"
|
#include "RFControl.h"
|
||||||
#include "PwmPin.h"
|
#include "PwmPin.h"
|
||||||
|
|
||||||
class sk68xx {
|
class Pixel {
|
||||||
private:
|
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;
|
RFControl *rf;
|
||||||
void loadColor(uint8_t c);
|
void loadColor(uint8_t c);
|
||||||
|
|
||||||
public:
|
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 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]
|
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
|
operator bool(){ // override boolean operator to return true/false if creation succeeded/failed
|
||||||
return(*rf);
|
return(*rf);
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,15 @@ void setup() {
|
||||||
|
|
||||||
Serial.println("\n\nHomeSpan Pixel Example\n\n");
|
Serial.println("\n\nHomeSpan Pixel Example\n\n");
|
||||||
|
|
||||||
sk68xx px(8);
|
Pixel px(8);
|
||||||
sk68xx test7(7);
|
Pixel test7(7);
|
||||||
sk68xx test6(6);
|
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 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");
|
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);
|
px.setHSV(60,0.9,0.5);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
px.setHSV(120,0.9,0.5);
|
px.setHSV(120,0.9,0.5);
|
||||||
|
|
@ -27,18 +27,18 @@ while(1){
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
while(1);
|
|
||||||
|
|
||||||
while(1){
|
|
||||||
for(int i=0;i<50;i++){
|
// while(1){
|
||||||
px.setRGB(i,0,0);
|
// for(int i=0;i<50;i++){
|
||||||
delay(2);
|
// px.setRGB(i,0,0);
|
||||||
}
|
// delay(2);
|
||||||
for(int i=50;i>=0;i--){
|
// }
|
||||||
px.setRGB(i,0,0);
|
// for(int i=50;i>=0;i--){
|
||||||
delay(2);
|
// px.setRGB(i,0,0);
|
||||||
}
|
// delay(2);
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
Serial.println("Done!");
|
Serial.println("Done!");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue