Created
June 22, 2018 18:49
-
-
Save mnemocron/da48a042097ed622ed62da92b0ee6400 to your computer and use it in GitHub Desktop.
Inherited Class from Adafruit_PWMServoDriver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RGBWDriver : public Adafruit_PWMServoDriver | |
{ | |
private: | |
uint8_t ch_R; | |
uint8_t ch_G; | |
uint8_t ch_B; | |
uint8_t ch_W; | |
void setChannels(uint8_t r, uint8_t g, uint8_t b, uint8_t w) | |
{ | |
this->ch_R = r; | |
this->ch_G = g; | |
this->ch_B = b; | |
this->ch_W = w; | |
}; | |
public: | |
RGBWDriver(uint8_t r, uint8_t g, uint8_t b, uint8_t w):Adafruit_PWMServoDriver() | |
{ | |
this->setChannels(r, g, b, w); | |
}; | |
RGBWDriver(uint8_t addr, uint8_t r, uint8_t g, uint8_t b, uint8_t w):Adafruit_PWMServoDriver(addr) | |
{ | |
this->setChannels(r, g, b, w); | |
}; | |
RGBWDriver(TwoWire *i2c, uint8_t addr, uint8_t r, uint8_t g, uint8_t b, uint8_t w):Adafruit_PWMServoDriver(i2c, addr) | |
{ | |
this->setChannels(r, g, b, w); | |
}; | |
void setColor(uint32_t c){ | |
uint8_t w = (uint8_t)(c >> 24); | |
uint8_t r = (uint8_t)(c >> 16), | |
uint8_t g = (uint8_t)(c >> 8), | |
uint8_t b = (uint8_t) c; | |
this->setColor(r, g, b, w); | |
} | |
void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t w){ | |
this->setPWM(this->ch_R, 0, (r*16) ); | |
this->setPWM(this->ch_G, 0, (g*16) ); | |
this->setPWM(this->ch_B, 0, (b*16) ); | |
this->setPWM(this->ch_W, 0, (w*16) ); | |
} | |
// Convert separate R,G,B into packed 32-bit RGB color. | |
// Packed format is always RGB, regardless of LED strand color order. | |
uint32_t Adafruit_NeoPixel::Color(uint8_t r, uint8_t g, uint8_t b) { | |
return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b; | |
} | |
// Convert separate R,G,B,W into packed 32-bit WRGB color. | |
// Packed format is always WRGB, regardless of LED strand color order. | |
uint32_t Adafruit_NeoPixel::Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) { | |
return ((uint32_t)w << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment