So I am trying to do the following effect: Titan Homes Stair Lighting - YouTube
This is the library I'm using: GitHub - ulrichstern/Tlc59711: Arduino library for controlling TI's TLC59711 (or TLC5971)
Here is my current code for fading one led. Can you help on applying that to up to 6?
void brighten() {
for (int i=0; i <= 65535; i+=200){
tlc.setChannel(5, i);
tlc.write();
delay(5);
}
}
Without looking too closely and without the full code, it sounds like a job for an array of LED pin numbers. What are the 2 parameters to the setChannel() function ? They look like pin number and level in which case an array of pin numbers would do what you want.
Yes its pin number (channel) and brightness. An array would work but how do I implement that in the for loop?
#include <Tlc59711.h>
const int NUM_TLC = 1;
Tlc59711 tlc(NUM_TLC);
void setup() {
tlc.beginFast();
}
void loop() {
brighten();
}
void brighten() {
for (int i=0; i <= 65535; i+=200){
tlc.setChannel(5, i);
tlc.write();
delay(5);
}
}
how do I implement that in the for loop?
Create an array of LED pin numbers. Use a for loop to iterate through the array then pass the value from the array , ie the pin number, to your brighten() function and use it instead of the fixed pin number in that for loop. Alternatively put an outer for loop in the function to iterate through the array and read the pin numbers from the array.
Note that both methods will block the free running of the loop() function which would prevent you from reading inputs etc should you need to.
void brighten() {
for (int i=0; i <= 65535; i+=200){
for(int j = 0; j<NUMBER_OF_CHANNELS; j++) {
tlc.setChannel(channel[j], i);
}
tlc.write();
delay(5);
}
}