Eine erweiterte Version, ist aber noch nicht die finale Version !
Teil 1:
#include "Tlc5940.h"
char* PatternFrame[] = { "00000000000000000000000000000000",
"0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f",
"f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0",
"000000f00000000f000000f00000000f",
"55555555555555555555555555555555",
"cccccccccccccccccccccccccccccccc",
"ffffffffffffffffffffffffffffffff",
"13579bdffdb9753113579bdffdb97531",
"13579bdf13579bdf13579bdf13579bdf",
"fdb97531fdb97531fdb97531fdb97531",
"0123456789abcdef0123456789abcdef",
"fedcba987654321ßfedcba9876543210"
};
char* Frame;
int Light1[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int Light2[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
byte Zaehler;
byte Zufall;
byte Zufall2;
void setup()
{
Tlc.init();
Tlc.clear();
Tlc.update();
randomSeed(analogRead(0));
}
void loop()
{
Zufall = random(1, 12);
if (Zufall == 1)
{
RandomLightFading(Light1, 200, 2);
PatternFading(Light1, PatternFrame[0], 5);
}
if (Zufall == 2)
{
for (Zaehler = 1; Zaehler <= 10; Zaehler += 1)
{
PatternFading(Light1, PatternFrame[1], 20);
delay(1000);
PatternFading(Light1, PatternFrame[2], 20);
delay(1000);
}
PatternFading(Light1, PatternFrame[0], 5);
}
if (Zufall == 3)
{
for (Zaehler = 0; Zaehler <= 200; Zaehler += 1)
{
SetPattern(Light1, PatternFrame[1]);
delay(150);
SetPattern(Light1, PatternFrame[2]);
delay(150);
}
SetPattern(Light1, PatternFrame[0]);
}
if (Zufall == 4)
{
DeclareParam(1931,3229,4095,3229,1931,740,200,740,1931,3229,4095,3229,1931,740,200,740,1931,3229,4095,3229,1931,740,200,740,1931,3229,4095,3229,1931,740,200,740);
ParamFading(Light1, Light2, 25);
delay(500);
Zufall2 = random(1, 101);
if (Zufall2 <= 50)
{ Zufall2 = 0; }
else { Zufall2 = 1; }
Drehen(Light1, 750, Zufall2, 75);
delay(500);
PatternFading(Light1, PatternFrame[0], 25);
}
if (Zufall == 5)
{
PatternFading(Light1, PatternFrame[7], 25);
delay(500);
Zufall2 = random(1, 101);
if (Zufall2 <= 50)
{ Zufall2 = 0; }
else { Zufall2 = 1; }
Drehen(Light1, 750, Zufall2, 75);
delay(500);
PatternFading(Light1, PatternFrame[0], 25);
}
if (Zufall == 6)
{
PatternFading(Light1, PatternFrame[8], 25);
delay(500);
Drehen(Light1, 1500, 1, 50);
delay(500);
PatternFading(Light1, PatternFrame[0], 25);
}
if (Zufall == 7)
{
PatternFading(Light1, PatternFrame[9], 25);
delay(500);
Drehen(Light1, 1500, 0, 50);
delay(500);
PatternFading(Light1, PatternFrame[0], 25);
}
if (Zufall == 8)
{
PatternFading(Light1, PatternFrame[10], 25);
delay(500);
Drehen(Light1, 1500, 1, 35);
delay(500);
PatternFading(Light1, PatternFrame[0], 25);
}
if (Zufall == 9)
{
PatternFading(Light1, PatternFrame[11], 25);
delay(500);
Drehen(Light1, 1500, 0, 35);
delay(500);
PatternFading(Light1, PatternFrame[0], 25);
}
if (Zufall == 10)
{
RandomLightFading(Light1, 200, 2);
SetPattern(Light1, PatternFrame[0]);
}
if (Zufall == 11)
{
for(byte Anzahl = 1; Anzahl <= 5; Anzahl += 1)
{
FlashStorm(240, 16);
}
}
delay(1000);
}
void Flash(int LightOld[32])
{
SetPattern(LightOld, PatternFrame[0]);
delay(1);
PatternFading(LightOld, PatternFrame[4], 1);
SetPattern(LightOld, PatternFrame[0]);
PatternFading(LightOld, PatternFrame[5], 1);
SetPattern(LightOld, PatternFrame[0]);
PatternFading(LightOld, PatternFrame[6], 1);
delay(1);
SetPattern(LightOld, PatternFrame[0]);
}
void FlashStorm(int AnzahlBlitze, byte MaxAnzahlLeds)
{
float Flash1Fade = 13.65;
float Flash2Fade = 27.3;
float Flash3Fade = 40.95;
int Helligkeit[32];
int BlitzeBisher = 0;
int BlitzeAktiv = 0;
int BlitzAktiv[32];
for(int LedNr = 0; LedNr <= 31; LedNr += 1)
{
Helligkeit[LedNr] = 0;
BlitzAktiv[LedNr] = 0;
Tlc.set(LedNr, Helligkeit[LedNr]);
}
Tlc.update();
delay(1);
while(BlitzeBisher < AnzahlBlitze)
{
for(byte BlitzNr = 1; BlitzNr <= MaxAnzahlLeds; BlitzNr += 1)
{
int LedNr;
LedNr = random(0, 32);
if((BlitzAktiv[LedNr] == 0) and (BlitzeAktiv < MaxAnzahlLeds) and (BlitzeBisher < AnzahlBlitze))
{
BlitzAktiv[LedNr] = 1;
BlitzeAktiv = BlitzeAktiv + 1;
}
}
for (int FlashFadingStep = 1; FlashFadingStep <= 100; FlashFadingStep += 1)
{
for (int Channel = 0; Channel <= 31; Channel += 1)
{
if(BlitzAktiv[Channel] == 1) Helligkeit[Channel] = Flash1Fade * FlashFadingStep;
if(BlitzAktiv[Channel] == 2) Helligkeit[Channel] = Flash2Fade * FlashFadingStep;
if(BlitzAktiv[Channel] == 3) Helligkeit[Channel] = Flash3Fade * FlashFadingStep;
Tlc.set(Channel, Helligkeit[Channel]);
}
Tlc.update();
delayMicroseconds(1500); // delay(1);
}
for (int Channel = 0; Channel <= 31; Channel += 1)
{
if(BlitzAktiv[Channel] != 0) BlitzAktiv[Channel] = BlitzAktiv[Channel] + 1;
if(BlitzAktiv[Channel] > 3)
{
BlitzAktiv[Channel] = 0;
BlitzeAktiv = BlitzeAktiv - 1;
Helligkeit[Channel] = 0;
BlitzeBisher = BlitzeBisher + 1;
}
}
for (int Channel = 0; Channel <= 31; Channel += 1)
{
Tlc.set(Channel, Helligkeit[Channel]);
}
Tlc.update();
delay(1);
}
for (int Channel = 0; Channel <= 31; Channel += 1)
{
Light1[Channel] = 0;
Tlc.set(Channel, 0);
}
Tlc.update();
delay(1);
}
void RandomLightFading(int LightOld[32], int Wiederholung, int Geschw)
{
float Fade[32];
int Helligkeit[32];
for (int Nr = 1; Nr <= Wiederholung; Nr += 1)
{
for (int LightNr = 0; LightNr <= 31; LightNr += 1)
{
Helligkeit[LightNr] = random(4095);
Fade[LightNr] = (Helligkeit[LightNr] - LightOld[LightNr])/100;
}
for (int Anzahl = 1; Anzahl <= 100; Anzahl += 1)
{
for (int Channel = 0; Channel <= 31; Channel += 1)
{
Tlc.set(Channel, LightOld[Channel] + (Anzahl * Fade[Channel]));
}
Tlc.update();
delay(Geschw);
}
for (int Channel = 0; Channel <= 31; Channel += 1)
{
Tlc.set(Channel, Helligkeit[Channel]);
Light1[Channel] = Helligkeit[Channel];
}
Tlc.update();
}
}
void RandomLight(int LightOld[32], int Wiederholung, int Geschw)
{
int Helligkeit[32];
for (int Nr = 1; Nr <= Wiederholung; Nr += 1)
{
for (int LightNr = 0; LightNr <= 31; LightNr += 1)
{
Helligkeit[LightNr] = random(4095);
}
for (int Anzahl = 1; Anzahl <= 100; Anzahl += 1)
{
for (int Channel = 0; Channel <= 31; Channel += 1)
{
Tlc.set(Channel, Helligkeit[Channel]);
}
Tlc.update();
delay(Geschw);
}
}
for (int Channel = 0; Channel <= 31; Channel += 1)
{
Light1[Channel] = Helligkeit[Channel];
}
}