Skip to content

Commit

Permalink
added brightness control
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffmannjan committed Apr 4, 2019
1 parent 4471a82 commit c9df7f3
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 7 deletions.
54 changes: 52 additions & 2 deletions Adafruit_TLC59711.cpp
Expand Up @@ -33,7 +33,7 @@ Adafruit_TLC59711::Adafruit_TLC59711(uint8_t n, uint8_t c, uint8_t d) {
_clk = c;
_dat = d;

BCr = BCg = BCb = 0x7F;
BCr = BCg = BCb = 0x7F; // default 100% brigthness

pwmbuffer = (uint16_t *)calloc(2, 12 * n);
}
Expand All @@ -51,7 +51,7 @@ Adafruit_TLC59711::Adafruit_TLC59711(uint8_t n, SPIClass *theSPI) {
_dat = -1;
_spi = theSPI;

BCr = BCg = BCb = 0x7F;
BCr = BCg = BCb = 0x7F; // default 100% brigthness

pwmbuffer = (uint16_t *)calloc(2, 12 * n);
}
Expand Down Expand Up @@ -157,6 +157,56 @@ void Adafruit_TLC59711::setLED(uint8_t lednum, uint16_t r, uint16_t g,
setPWM(lednum * 3 + 2, b);
}

/*!
* @brief Set the brightness of LED channels to same value
* @param BC
* Brightness Control value
*/
void Adafruit_TLC59711::simpleSetBrightness(uint8_t BC) {
if (BC > 127) {
BC = 127; // maximum possible value since BC can only be 7 bit
} else if (BC < 0) {
BC = 0;
}

BCr = BCg = BCb = BC;
}

/*!
* @brief Set the brightness of LED channels to specific value
* @param bcr
* Brightness Control Red value
* @param bcg
* Brightness Control Green value
* @param bcb
* Brightness Control Blue value
*/
void Adafruit_TLC59711::setBrightness(uint8_t bcr, uint8_t bcg, uint8_t bcb) {
if (bcr > 127) {
bcr = 127; // maximum possible value since BC can only be 7 bit
} else if (bcr < 0) {
bcr = 0;
}

BCr = bcr;

if (bcg > 127) {
bcg = 127; // maximum possible value since BC can only be 7 bit
} else if (bcg < 0) {
bcg = 0;
}

BCg = bcg;

if (bcb > 127) {
bcb = 127; // maximum possible value since BC can only be 7 bit
} else if (bcb < 0) {
bcb = 0;
}

BCb = bcb;
}

/*!
* @brief Begins SPI connection if there is not empty PWM buffer
* @return If successful returns true, otherwise false
Expand Down
8 changes: 4 additions & 4 deletions Adafruit_TLC59711.h
Expand Up @@ -30,7 +30,7 @@
* TLC59711 Senor
*/
class Adafruit_TLC59711 {
public:
public:
Adafruit_TLC59711(uint8_t n, uint8_t c, uint8_t d);
Adafruit_TLC59711(uint8_t n, SPIClass *theSPI = &SPI);

Expand All @@ -40,15 +40,15 @@ class Adafruit_TLC59711 {
void setLED(uint8_t lednum, uint16_t r, uint16_t g, uint16_t b);
void write();
void spiwriteMSB(uint8_t d);
void setBrightness(uint8_t bcr, uint8_t bcg, uint8_t bcb);
void simpleSetBrightness(uint8_t BC);

private:
private:
uint16_t *pwmbuffer;

uint8_t BCr, BCg, BCb;
int8_t numdrivers, _clk, _dat;
SPIClass *_spi;

};


#endif
15 changes: 14 additions & 1 deletion examples/tlc59711test/tlc59711test.ino
Expand Up @@ -44,7 +44,7 @@ void loop() {
colorWipe(0, 0, 65535, 100); // "Blue" (depending on your LED wiring)
delay(200);

rainbowCycle(5);
increaseBrightness();
}


Expand Down Expand Up @@ -83,3 +83,16 @@ void Wheel(uint8_t ledn, uint16_t WheelPos) {
tlc.setLED(ledn, 0, 3*WheelPos, 65535 - 3*WheelPos);
}
}

//All RGB Channels on full colour
//Cycles trough all brightness settings from 0 up to 127
void increaseBrightness(){
for(uint16_t i=0; i<8*NUM_TLC59711; i++) {
tlc.setLED(i, 65535, 65535, 65535);
}
for(int i = 0; i < 128; i++){
tlc.simpleSetBrightness(i);
tlc.write();
delay(1000);
}
}

0 comments on commit c9df7f3

Please sign in to comment.