I'm trying to create a very simple RGB-rainbow-like sequence with the Adafruit 12-Channel 16-bit PWM LED Driver controlled via SPI from a Arduino Pro Mini via SPI. In the final setup the Adafruit should control 4 RGB LED Strips with a common 12V connection, which will have their own power supply then:
For easier debugging, I replaced the LED strips with red, green and blue single LEDs (on only 2 of 4 channels): After a lot of testing, it seems that the sample code from Adafruit is somehow not working as intended (alltough I can not really imagine that). I'm no programmer by any means so that's why I have a hard time figuring out what the problem really is.
My Setup:
My simple setup consists out of the Arduino, the TLC59711 breakout board and 6 LEDs for currently two channels assembled as shown in my quick and dirty schematic.
My Code
The code shown here is the example code that comes with the Adafruit Breakout Board. The code compiles without any problems.
Code: Select all
#include "Adafruit_TLC59711.h"
#include <SPI.h>
// How many boards do you have chained?
#define NUM_TLC59711 1
#define data 11
#define clock 13
Adafruit_TLC59711 tlc = Adafruit_TLC59711(NUM_TLC59711, clock, data);
//Adafruit_TLC59711 tlc = Adafruit_TLC59711(NUM_TLC59711);
void setup() {
Serial.begin(9600);
Serial.println("TLC59711 test");
tlc.begin();
tlc.write();
rainbow(5); // the function I want to work with
}
void loop()
{
colorWipe(65535, 0, 0, 100); // "Red" //"wipe" means to me "turn off" but in this case red gets turned on.
delay(200);
colorWipe(0, 65535, 0, 100); // "Green"
delay(200);
colorWipe(0, 0, 65535, 100); // "Blue"
delay(200);
}
// Fill the dots one after the other with a color
void colorWipe(uint16_t r, uint16_t g, uint16_t b, uint8_t wait) {
for(uint16_t i=0; i<8*NUM_TLC59711; i++) {
tlc.setLED(i, r, g, b);
tlc.write();
delay(wait);
}
}
// Rainbow all LEDs at the same time, same color
void rainbow(uint8_t wait) {
uint32_t i, j;
for(j=0; j<65535; j+=10) {
for(i=0; i<4*NUM_TLC59711; i++) {
Wheel(i, (i+j) & 65535);
}
tlc.write();
delay(wait);
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint32_t i, j;
for(j=0; j<65535; j+=10) { // 1 cycle of all colors on wheel
for(i=0; i < 4*NUM_TLC59711; i++) {
Wheel(i, ((i * 65535 / (4*NUM_TLC59711)) + j) & 65535);
}
tlc.write();
delay(wait);
}
}
// Input a value 0 to 4095 to get a color value.
// The colours are a transition r - g - b - back to r.
void Wheel(uint8_t ledn, uint16_t WheelPos) {
if(WheelPos < 21845) {
tlc.setLED(ledn, 3*WheelPos, 65535 - 3*WheelPos, 0);
} else if(WheelPos < 43690) {
WheelPos -= 21845;
tlc.setLED(ledn, 65535 - 3*WheelPos, 0, 3*WheelPos);
} else {
WheelPos -= 43690;
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);
}
}
The main issue I have with that "rainbow" function is, that I get a lot of LED flickering when executing it. You can find a video of it here: https://youtu.be/WvfPnrw17g4. Ignore the MOSFETs in the Background, they are disabled. The video shows the functional schematic from the second picture [2]. There is no smooth transition between the colors but more the fear of getting an epileptic seizure. The Power supply is not the problem, it can deliver enough current. If I turn on the LEDs statically e.g. with the function "colorWipe" then there's no flickering. I have the same issue with the LED Strips, where I control them via individual MOSFET.
What I want
A smooth rainbow-like color fade throughout all 4 LED strips. Like CH0 should e.g. start with red, CH1 with orange, CH2 with green and CH3 with blue. This should fade then with all the colors in between from CH0 to CH3 in a endless loop:
Since I tried so many different things (single LEDs vs Strips, MOSFETs, even BJ Transistors) and since I get this flickering every time with this "rainbow" (with "rainbowCycle" as well) function, I think that the code somehow is the crux of the matter. Has anyone of you an idea? If you need more Information please ask! And sorry if I forgot something to mention. Thanks in advance!