Ich habe in einigen Beiträgen gelesen das es eine Bibliothekk für den TLC5940 gibt. Wo kann man die den bekommen ?
Mit den Suchbegriffen "arduino library 5940" habe ich bei Google viele Einträge gefunden.
Kuckst du hier, um mit deinen neuen Chips Freude zu haben:
Für doppelt Freude:
Natürlich lässt sich der TLC5940 nicht nur als LED-Treiber sondern auch als PWM Expander einsetzen.
http://fritzing.org/projects/pwm-expander-rgb-ledsservos/
Hat man zuwenig PWM-Kanäle, dann nimmt man halt einen TLC5940 dafür !
Ein kleines Programm für die TLC5940 Library und 10 Leds.
#include "Tlc5940.h"
int light[10];
int light2[40];
int hilfs;
void setup()
{
light[0] = 400;
light[1] = 800;
light[2] = 1200;
light[3] = 1600;
light[4] = 2000;
light[5] = 2400;
light[6] = 2800;
light[7] = 3200;
light[8] = 3600;
light[9] = 4000;
light2[0] = 0;
light2[1] = 0;
light2[2] = 0;
light2[3] = 0;
light2[4] = 0;
light2[5] = 0;
light2[6] = 0;
light2[7] = 0;
light2[8] = 0;
light2[9] = 0;
light2[10] = 0;
light2[11] = 0;
light2[12] = 0;
light2[13] = 0;
light2[14] = 0;
light2[15] = 400;
light2[16] = 800;
light2[17] = 1200;
light2[18] = 1600;
light2[19] = 2000;
light2[20] = 2400;
light2[21] = 2800;
light2[22] = 3200;
light2[23] = 3600;
light2[24] = 4000;
light2[25] = 0;
light2[26] = 0;
light2[27] = 0;
light2[28] = 0;
light2[29] = 0;
light2[30] = 0;
light2[31] = 0;
light2[32] = 0;
light2[33] = 0;
light2[34] = 0;
light2[35] = 0;
light2[36] = 0;
light2[37] = 0;
light2[38] = 0;
light2[39] = 0;
Tlc.init();
}
void loop()
{
// Auf der einen Seite raus und auf der anderen wieder rein
for (int anzahl = 1; anzahl <= 100; anzahl += 1)
{
for (int channel = 0; channel <= 9; channel += 1)
{
Tlc.set(channel, light[channel]);
}
Tlc.update();
delay(50);
for (int channel = 9; channel >= 1; channel -= 1)
{
hilfs = light[channel];
light[channel] = light[channel - 1];
light[channel - 1] = hilfs;
}
}
// Laufschrift Prinzip
for (int anzahl = 1; anzahl <= 10; anzahl += 1)
{
for (int lightnr = 30; lightnr >= 0; lightnr -= 1)
{
for (int channel = 0; channel <= 9; channel += 1)
{
Tlc.set(channel, light2[lightnr + channel]);
}
Tlc.update();
delay(40);
}
}
}
Vielleicht findet es jemand nützlich !
Simple fading mit 10 Leds für Anfänger:
#include "Tlc5940.h"
int light1[10];
int light2[10];
float fade[10];
void setup()
{
light1[0] = 0;
light1[1] = 0;
light1[2] = 0;
light1[3] = 0;
light1[4] = 0;
light1[5] = 0;
light1[6] = 0;
light1[7] = 0;
light1[8] = 0;
light1[9] = 0;
Tlc.init();
}
void loop()
{
for (int nr = 0; nr <= 9; nr += 1)
{
light2[nr] = light1[nr];
light1[nr] = random(4095);
fade[nr] = (light1[nr] - light2[nr])/200;
}
for (int anzahl = 1; anzahl <= 200; anzahl += 1)
{
for (int channel = 0; channel <= 9; channel += 1)
{
Tlc.set(channel, light2[channel] + (anzahl * fade[channel]));
}
Tlc.update();
delay(1);
}
}
Jede Led wird in 200 Schritten von der aktuellen Helligkeit auf die neue Soll-Helligkeit gedimmt. Diese kann heller oder dunkler als die vorherige sein !
Pattern Fading mit 10 Leds. Von einem Helligkeitszustand zum nächsten.
#include "Tlc5940.h"
int light0[10] = {0,0,0,0,0,0,0,0,0,0};
int light1[10] = {0,4095,0,4095,0,4095,0,4095,0,4095};
int light2[10] = {4095,0,4095,0,4095,0,4095,0,4095,0};
int light3[10] = {0,250,1000,2500,4095,4095,2500,1000,250,0};
int light4[10] = {4095,2500,1000,250,0,0,250,1000,2500,4095};
void setup()
{
Tlc.init();
}
void loop()
{
fading(light0, light1);
fading(light1, light2);
fading(light2, light0);
fading(light0, light3);
fading(light3, light4);
fading(light4, light0);
}
void fading(int lightold[10], int lightnew[10])
{
float fade[10];
for (int nr = 0; nr <= 9; nr += 1)
{
fade[nr] = (lightnew[nr] - lightold[nr])/200;
}
for (int anzahl = 1; anzahl <= 200; anzahl += 1)
{
for (int channel = 0; channel <= 9; channel += 1)
{
Tlc.set(channel, lightold[channel] + (anzahl * fade[channel]));
}
Tlc.update();
delay(15);
}
for (int channel = 0; channel <= 9; channel += 1)
{
Tlc.set(channel, lightnew[channel]);
}
Tlc.update();
delay(1000);
}
Als Weiterentwicklung dann noch Pattern Fading mit Geschwindigkeitssteuerung.
#include "Tlc5940.h"
int light0[10] = {0,0,0,0,0,0,0,0,0,0};
int light1[10] = {0,250,1000,2500,4095,4095,2500,1000,250,0};
void setup()
{
Tlc.init();
}
void loop()
{
for (int ges = 1; ges <= 25; ges += 2)
{
fading(light0, light1, ges);
fading(light1, light0, ges);
}
}
void fading(int lightold[10], int lightnew[10], int geschw)
{
float fade[10];
// geschw = geschw * 1000; Hier könnte der Faktor auch 100 oder 10 sein !
for (int nr = 0; nr <= 9; nr += 1)
{
fade[nr] = (lightnew[nr] - lightold[nr])/100;
}
for (int anzahl = 1; anzahl <= 100; anzahl += 1)
{
for (int channel = 0; channel <= 9; channel += 1)
{
Tlc.set(channel, lightold[channel] + (anzahl * fade[channel]));
}
Tlc.update();
delay(geschw); // delayMicroseconds(geschw); Hier kann delay durch delayMicroseconds ersetzt werden
}
for (int channel = 0; channel <= 9; channel += 1)
{
Tlc.set(channel, lightnew[channel]);
}
Tlc.update();
}
Für 10 Leds. Eine kleine patterngesteuerte Animation.
#include "Tlc5940.h"
char* PatternFrame[] = {"0000030000",
"0000030000",
"0000030000",
"0000030000",
"0000030000",
"3000030000",
"1230030000",
"0012330000",
"0001233000",
"0003213000",
"0321003000",
"0123003000",
"0001233000",
"0000123300",
"0000321300",
"0032100300",
"0012300300",
"0000123300",
"0000012330",
"0000032130",
"0003210030",
"0321000030",
"0123000030",
"0001230030",
"0000012330",
"0000000123",
"0000000321",
"0000003210",
"0000032100",
"0000031000",
"0000030000",
"0000030000",
"0000030000",
"0000020000",
"0000010000",
"0000020000",
"0000030000",
"0000020000",
"0000010000",
"0000020000",
"0000030000",
"0003210000",
"0321000000",
"2100000000",
"0000000000",
"0000000000",
"0000000000",
"0000000000",
"0000000000",
"0000000001",
"0000000010",
"0000000200",
"0000002000"};
char* Frame;
byte Helligkeit;
void setup()
{
Tlc.init();
Tlc.clear();
Tlc.update();
}
void loop()
{
for (int FrameNr = 0; FrameNr <= 52; FrameNr += 1)
{
Frame = PatternFrame[FrameNr];
for (int Channel = 0; Channel <= 9; Channel += 1)
{
Helligkeit = byte(char(Frame[Channel])) -48;
if (Helligkeit > 0)
{
Tlc.set(Channel, ((Helligkeit - 1) * 1500) + 1095);
}
else
{
Tlc.set(Channel, 0);
}
}
Tlc.update();
delay(100);
}
}
Für 10 Leds. Die Benutzung einer Sinuswert-Tabelle.
#include "Tlc5940.h"
byte PatternFrame[112] = {128,136,144,151,159,167,174,181,188,195,201,208,214,219,224,229,
234,238,242,245,248,250,252,253,254,255,255,254,253,252,250,248,
245,242,238,234,229,224,219,214,208,201,195,188,181,174,167,159,
151,144,136,128,120,112,105,97,89,82,75,68,61,55,48,42,
37,32,27,22,18,14,11,8,6,4,3,2,1,1,2,3,
4,6,8,11,14,18,22,27,32,37,42,48,55,61,68,75,
82,89,97,105,112,120,128,128,136,144,151,159,167,174,181,188};
int Helligkeit;
void setup()
{
Tlc.init();
Tlc.clear();
Tlc.update();
}
void loop()
{
for (byte Zeit = 50; Zeit >= 1; Zeit -= 2)
{
for (int FrameNr = 0; FrameNr <= 102; FrameNr += 1)
{
for (int Channel = 0; Channel <= 9; Channel += 1)
{
Helligkeit = (PatternFrame[FrameNr + Channel] * 15) + 250;
Tlc.set(Channel, Helligkeit);
}
Tlc.update();
delay(Zeit);
}
}
}