Here is my next project - the effects are taken from Effects
I don't know how to upload a video here - so here is a link : Video
Some pictures: Picture 1 Picture 2 Picture 3 Picture 4
And the code:
//Stromaufnahme (gemessen) wenn alle 101 LEds weiß maximal leuchten: ca. 2,8A
//Version 12 ist final
//Millennium falke Normen Altiparmak
#include <FastLED.h>
#define LED_PIN 10 //Pin der Datenleitung zu dem LED-Strip
#define NUM_LEDS 101 //segmente (6*15)+ 2 antrieb+ 9 kanzel
//#define LED_TYPE WS2812B
//#define LED_TYPE WS2811
//#define LED_TYPE WS2801 - der definiert nicht
//#define LED_TYPE UCS1903 - der definiert nicht
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
#define HELLIGKEITS_STUFE 20
#define MINIMALE_HELLIGKEIT 10
CRGB leds[NUM_LEDS]; //speichert die LED-Farbwerte
int status =-1;
int laststatus=-1;
volatile unsigned long alteZeit=0, entprellZeit=100; //fuer heller und dunkler verwendet
static unsigned long lastMillis = 0; //als einschlaftimer verwendet
int brightness = 100; //startwert
int temp = 0;
int tempbrightness=0;
unsigned char antriebblinkzaehler=0;
unsigned char antriebblinkteiler=0;
byte colors[3][3] = { {0xff, 0x00, 0x00},{0xff, 0xff, 0xff}, {0x00, 0x00, 0xff} };
void setup()
{
Serial.begin(9600);
//configure pin 2 as an input and enable the internal pull-up resistor
pinMode(A0, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
pinMode(A3, INPUT_PULLUP);
pinMode(A4, INPUT_PULLUP);
pinMode(A5, INPUT_PULLUP);
pinMode( 8, INPUT_PULLUP);
pinMode( 9, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP); //dunkler
pinMode(3, INPUT_PULLUP); //heller
//attachInterrupt(digitalPinToInterrupt(2), dunkler, FALLING);
//attachInterrupt(digitalPinToInterrupt(3), heller, FALLING);
attachInterrupt(digitalPinToInterrupt(2), dunkler, LOW);
attachInterrupt(digitalPinToInterrupt(3), heller, LOW);
FastLED.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); // initializes LED strip - vorne 256
setAll (255,255,255);
FastLED.setBrightness (brightness);
FastLED.show();
Serial.println("Startup Eddys Falke");
}
int readstatus ()
{
if (digitalRead(A0)==0) return 5; //
if (digitalRead(A1)==0) return 6; //
if (digitalRead(A2)==0) return 7; //
if (digitalRead(A3)==0) return 8; //
if (digitalRead(A4)==0) return 9; //
if (digitalRead(A5)==0) return 10; //
if (digitalRead( 8)==0) return 0; //
if (digitalRead( 9)==0) return 11; //
if (digitalRead( 4)==0) return 1;
if (digitalRead( 5)==0) return 2; //
if (digitalRead( 6)==0) return 3; //
if (digitalRead( 7)==0) return 4; //
return -1;
}
void dunkler()
{
if((millis() - alteZeit) > entprellZeit) {
temp = brightness - HELLIGKEITS_STUFE;
if (temp>HELLIGKEITS_STUFE)
{
brightness = brightness - HELLIGKEITS_STUFE;
FastLED.setBrightness (brightness);
}
else
{
brightness = MINIMALE_HELLIGKEIT;
FastLED.setBrightness (brightness);
}
alteZeit = millis(); // letzte Schaltzeit merken
}
}
void heller()
{
if((millis() - alteZeit) > entprellZeit) {
// innerhalb der entprellZeit nichts machen
//Serial.println("heller");
temp = brightness + HELLIGKEITS_STUFE;
if (temp<=255)
{
brightness = brightness + HELLIGKEITS_STUFE;
FastLED.setBrightness (brightness);
}
else
{
brightness = 255;
FastLED.setBrightness (brightness);
}
alteZeit = millis(); // letzte Schaltzeit merken
}
}
void dimout (int wartezeit)
{
for (tempbrightness=brightness;tempbrightness>=0;tempbrightness--)
{
FastLED.setBrightness (tempbrightness);
FastLED.show();
delay (wartezeit);
}
delay (300);
}
void dimin (int wartezeit)
{
for (tempbrightness=0;brightness>=tempbrightness;tempbrightness++)
{
FastLED.setBrightness (tempbrightness);
FastLED.show();
delay (wartezeit);
}
}
void loop()
{
status=readstatus();
if (status!=-1)
{
//FastLED.setBrightness (brightness); //am Ende jeder Funktion wird runtergedimmt - daher hier wieder anschalten
Serial.print("Status: ");
Serial.print(status, DEC);
Serial.print(" / Helligkeit: ");
Serial.println(brightness, DEC);
switch (status)
{
case 0: {
schlaflicht (0); //schlaflicht dimmt selbst aus
} break;
case 1: {
normaleslicht (1);
dimout(3);
} break;
case 2: {
NewKITT(2,0xff, 0x00, 0x00, 8, 5, 50);
dimout(3);
} break;
case 3: {
meteorRain(3,0xff,0xff,0xff,10, 64, true, 50);
//delay (1000);
dimout(3);
} break;
case 4: {
theaterChaseRainbow(4,60);
dimout(3);
} break;
case 5: {
Fire(5,55,120,15);
dimout(3);
} break;
case 6: {
TwinkleRandom(6,20, 100, false);
dimout(3);
} break;
case 7: {
rainbowCycle(7,50);
dimout(3);
} break;
case 8: {
zufall(8,5);
dimout(3);
} break;
case 9: {
SnowSparkle(9,0x10, 0x10, 0x10, 20, random(100,1000));
dimout(3);
} break;
case 10: {
RunningLights(10, 50); // blue
dimout(3);
} break;
case 11: {
BouncingColoredBalls(11,3, colors, true);
dimout(3);
} break;
}
}
}
void zufall (int auswahl, int warten)
{
setAll(0,0,0);
dimin(1);
while (1)
{
setPixel(random(NUM_LEDS), random8(), random8(), random8());
FastLED.show();
if (readstatus()!=auswahl) return;
delay(warten);
}
}
void NewKITT(int auswahl, byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
setAllRing(0,0,0);
dimin(1);
RightToLeft(auswahl, red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
LeftToRight(auswahl, red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
OutsideToCenter(auswahl, red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
CenterToOutside(auswahl, red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
LeftToRight(auswahl, red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
RightToLeft(auswahl, red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
OutsideToCenter(auswahl, red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
CenterToOutside(auswahl, red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
}
// used by NewKITT
void CenterToOutside(int auswahl, byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for(int i =((90-EyeSize)/2); i>=0; i--) {
setAllRing(0,0,0);
setPixel(i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(i+j, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);
setPixel(90-i-1, red/10, green/10, blue/10);//bugfix aus text
for(int j = 1; j <= EyeSize; j++) {
setPixel(90-i-j, red, green, blue);
}
setPixel(90-i-EyeSize-1, red/10, green/10, blue/10);
showStrip();
if (readstatus()!=auswahl) return;
blinkantrieb();
delay(SpeedDelay);
}
if (readstatus()!=auswahl) return;
blinkantrieb();
delay(ReturnDelay);
}
// used by NewKITT
void OutsideToCenter(int auswahl, byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for(int i = 0; i<=((90-EyeSize)/2); i++) {
setAllRing(0,0,0);
setPixel(i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(i+j, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);
setPixel(90-i-1, red/10, green/10, blue/10);//bugfix aus text
for(int j = 1; j <= EyeSize; j++) {
setPixel(90-i-j, red, green, blue);
}
setPixel(90-i-EyeSize-1, red/10, green/10, blue/10);
showStrip();
if (readstatus()!=auswahl) return;
blinkantrieb();
delay(SpeedDelay);
}
if (readstatus()!=auswahl) return;
blinkantrieb();
delay(ReturnDelay);
}
// used by NewKITT
void LeftToRight(int auswahl, byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for(int i = 0; i < 90-EyeSize-2; i++) {
setAllRing(0,0,0);
setPixel(i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(i+j, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);
showStrip();
if (readstatus()!=auswahl) return;
blinkantrieb();
delay(SpeedDelay);
}
if (readstatus()!=auswahl) return;
blinkantrieb();
delay(ReturnDelay);
}
// used by NewKITT
void RightToLeft(int auswahl, byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for(int i = 90-EyeSize-2; i > 0; i--) {
setAllRing(0,0,0);
setPixel(i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(i+j, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);
showStrip();
if (readstatus()!=auswahl) return;
blinkantrieb();
delay(SpeedDelay);
}
if (readstatus()!=auswahl) return;
blinkantrieb();
delay(ReturnDelay);
}
// used by NewKITT
void blinkantrieb ()
{
int adder;
adder=random (9);
setPixel(92+adder,random8(), random8(), random8());
}
void schlaflicht(int auswahl)
{
unsigned int zaehler=0;
int i,j;
FastLED.setBrightness (0);
setAllRing (128,128,128);
setCockpit (128,0,0);
setAntrieb(0,0,128);
setRing (0,0,128,0);
setRing (5,128,0,128);
brightness=50;
dimin(2);
lastMillis = millis();
Serial.println("start schlafen");
zaehler=12000; //wird alle 10 ms runtergezaehlt
while (millis() - lastMillis <= 14400000)
//while (millis() - lastMillis <= 10000)
{
zaehler--;
if (zaehler==0)
{
zaehler=12000;
if (brightness>100) brightness--;
if (brightness>10) brightness--;
FastLED.setBrightness (brightness);
Serial.print("Hell: ");
Serial.println(brightness, DEC);
}
FastLED.show();
if (readstatus()!=auswahl)
{
dimout(3);
brightness=100; //die anderen funktionen kommen mit krummen werten nicht zurecht
return;
}
delay (10);
}
Serial.println("time to sleep");
for (i=1;i<5;i++) //die weissen ringe werden runtergefahren
{
for (j=128;j>=0;j--)
{
setRing(i,j,j,j);
delay(5);
}
delay(1000);
}
for (j=128;j>=0;j--) setAntrieb(0,0,j);
while(1)
{
if (readstatus()!=auswahl)
{
dimout(3);
brightness=100; //die anderen funktionen kommen mit krummen werten nicht zurecht
return;
}
FastLED.show();
delay (10);
}
}
void normaleslicht (int auswahl)
{
setAll (255,255,255);
setPixel(92,0,0,255);
setPixel(100,0,0,255);
setRing (0,0,0,255);
setRing (5,0,0,255);
dimin(2);
while (1)
{
FastLED.show();
if (readstatus()!=auswahl) return;
delay (10);
}
}
void allblue (int auswahl)
{
//Serial.println("start allblue");
//delay (3000);
setAll (0,0,255);
//Serial.println("start dimin");
//delay (3000);
dimin(2);
while (1)
{
FastLED.show();
if (readstatus()!=auswahl) return;
delay (10);
}
}
void SnowSparkle(int auswahl,byte red, byte green, byte blue, int SparkleDelay, int SpeedDelay) {
int i;
setAll(0,0,0);
dimin(1);
while (1)
{
setAll(0,0,0);
for (i=3;i< (random (100));i++)
{
int Pixel = random(NUM_LEDS)-1;
setPixel(Pixel,0xff,0xff,0xff);
if (readstatus()!=auswahl) return;
delay(SparkleDelay);
}
FastLED.show();
//delay(1);
}
}
void RunningLights(int auswahl, int WaveDelay) {
int Position=0;
unsigned char red,green,blue;
setAll (0,0,0);
dimin(1);
while (1)
{
for(int i=0; i<36; i++)
{
red=random(255);
green=random(255);
blue=random(255);
Position++; // = 0; //Position + Rate;
for(int i=0; i<NUM_LEDS; i++) {
// sine wave, 3 offset waves make a rainbow!
//float level = sin(i+Position) * 127 + 128;
//setPixel(i,level,0,0);
float level = sin(i+Position) * 127 + 128;
setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
((sin(i+Position) * 127 + 128)/255)*green,
((sin(i+Position) * 127 + 128)/255)*blue);
}
showStrip();
if (readstatus()!=auswahl) return;
delay(WaveDelay);
}
}
}
//used by fire
void setPixelHeatColor (int Pixel, byte temperature) {
// Scale 'heat' down from 0-255 to 0-191
byte t192 = round((temperature/255.0)*191);
// calculate ramp up from
byte heatramp = t192 & 0x3F; // 0..63
heatramp <<= 2; // scale up to 0..252
// figure out which third of the spectrum we're in:
if( t192 > 0x80) { // hottest
setPixel(Pixel, 255, 255, heatramp);
} else if( t192 > 0x40 ) { // middle
setPixel(Pixel, 255, heatramp, 0);
} else { // coolest
setPixel(Pixel, heatramp, 0, 0);
}
}
void Fire(int auswahl, int Cooling, int Sparking, int SpeedDelay) {
static byte heat[90];
int cooldown;
setAllRing(0,0,0);
setAntrieb(255,0,0);
setPixel(90,255,0,0);
setPixel(91,255,0,0);
dimin(1);
while (1)
{
// Step 1. Cool down every cell a little
for( int i = 0; i < 90; i++)
{
cooldown = random(0, ((Cooling * 10) / 90) + 2);
if(cooldown>heat[i]) heat[i]=0;
else heat[i]=heat[i]-cooldown;
}
// Step 2. Heat from each cell drifts 'up' and diffuses a little
for( int k= 90 - 1; k >= 2; k--) heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
// Step 3. Randomly ignite new 'sparks' near the bottom
if( random(255) < Sparking )
{
int y = random(7);
heat[y] = heat[y] + random(160,255);
}
// Step 4. Convert heat to LED colors
for( int j = 0; j < 90; j++) setPixelHeatColor(j, heat[j] );
FastLED.show();
if (readstatus()!=auswahl) return;
}
}
void meteorRain(int auswahl, byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
antriebblinkzaehler=0;
antriebblinkteiler=0;
setAll(0,0,0);
dimin(2);
while (1)
{
for(int i = 0; i < 180; i++) {
// fade brightness all LEDs one step
for(int j=0; j<90; j++) {
if( (!meteorRandomDecay) || (random(10)>5) ) {
fadeToBlack(j, meteorTrailDecay );
}
}
// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j <90) && (i-j>=0) ) {
setPixel(i-j, red, green, blue);
leds[90] = CHSV(random8(),random8(),random8()); // hue, saturation, value
leds[91] = CHSV(random8(),random8(),random8()); // hue, saturation, value
antriebblink();
}
}
showStrip();
if (readstatus()!=auswahl) return;
delay(SpeedDelay);
}
}
}
//used by meteorrain
void antriebblink ()
{
int i=0;
if (antriebblinkteiler%4==0)
{
for (i=92;i<101;i++) setPixel(i, 0, 0, antriebblinkzaehler);
antriebblinkzaehler++;
}
antriebblinkteiler++;
}
// used by meteorrain
void fadeToBlack(int ledNo, byte fadeValue) {
leds[ledNo].fadeToBlackBy( fadeValue );
leds[90] = CHSV(random8(),random8(),random8()); // cockpit blinken
leds[91] = CHSV(random8(),random8(),random8()); // cockpit blinken
antriebblink();
}
void theaterChaseRainbow(int auswahl, int SpeedDelay) {
byte *c;
setAll(0,0,0);
dimin(1);
while (1)
{
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < NUM_LEDS; i=i+3) {
c = Wheel( (i+j) % 255);
setPixel(i+q, *c, *(c+1), *(c+2)); //turn every third pixel on
}
showStrip();
delay(SpeedDelay);
if (readstatus()!=auswahl) return;
for (int i=0; i < NUM_LEDS; i=i+3) {
setPixel(i+q, 0,0,0); //turn every third pixel off
}
}
}
}
}
// used by rainbowCycle and theaterChaseRainbow
byte * Wheel(byte WheelPos) {
static byte c[3];
if(WheelPos < 85) {
c[0]=WheelPos * 3;
c[1]=255 - WheelPos * 3;
c[2]=0;
} else if(WheelPos < 170) {
WheelPos -= 85;
c[0]=255 - WheelPos * 3;
c[1]=0;
c[2]=WheelPos * 3;
} else {
WheelPos -= 170;
c[0]=0;
c[1]=WheelPos * 3;
c[2]=255 - WheelPos * 3;
}
return c;
}
void rainbowCycle(int auswahl, int SpeedDelay) {
byte *c;
uint16_t i, j;
setAll (0,0,0);
dimin(1);
while (1)
{
for(j=0; j<256*5; j++) // 5 cycles of all colors on wheel
{
for(i=1; i<= 92; i++)
{
c=Wheel(((i * 256 / 92) + j) & 255);
setPixel(i, *c, *(c+1), *(c+2));
}
setAntrieb (leds[48].red,leds[48].green,leds[48].blue);
FastLED.show();
if (readstatus()!=auswahl) return;
}
}
}
void BouncingColoredBalls(int auswahl, int BallCount, byte colors[][3], boolean continuous) {
float Gravity = -9.81;
int StartHeight = 1;
float Height[BallCount];
float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
float ImpactVelocity[BallCount];
float TimeSinceLastBounce[BallCount];
int Position[BallCount];
long ClockTimeSinceLastBounce[BallCount];
float Dampening[BallCount];
boolean ballBouncing[BallCount];
boolean ballsStillBouncing = true;
setAll(0,0,0);
setAntrieb(0,255,0);
setPixel(90, 0,255,255);
setPixel(91,255,255,0);
dimin(1);
for (int i = 0 ; i < BallCount ; i++) {
ClockTimeSinceLastBounce[i] = millis();
Height[i] = StartHeight;
Position[i] = 0;
ImpactVelocity[i] = ImpactVelocityStart;
TimeSinceLastBounce[i] = 0;
Dampening[i] = 0.90 - float(i)/pow(BallCount,2);
ballBouncing[i]=true;
}
while (ballsStillBouncing) {
for (int i = 0 ; i < BallCount ; i++) {
TimeSinceLastBounce[i] = millis() - ClockTimeSinceLastBounce[i];
Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
if ( Height[i] < 0 ) {
Height[i] = 0;
ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
ClockTimeSinceLastBounce[i] = millis();
if ( ImpactVelocity[i] < 0.01 ) {
if (continuous) {
ImpactVelocity[i] = ImpactVelocityStart;
} else {
ballBouncing[i]=false;
}
}
}
Position[i] = round( Height[i] * (90 - 1) / StartHeight);
}
ballsStillBouncing = false; // assume no balls bouncing
for (int i = 0 ; i < BallCount ; i++) {
setPixel(Position[i],colors[i][0],colors[i][1],colors[i][2]);
if ( ballBouncing[i] ) {
ballsStillBouncing = true;
}
}
showStrip();
if (readstatus()!=auswahl) return;
setAllRing(0,0,0);
}
}
void NOTUSED_RGBLoop(int auswahl){
setAll(0,0,0);
dimin(1);
for(int j = 0; j < 3; j++ ) {
// Fade IN
for(int k = 0; k < 256; k++) {
switch(j) {
case 0: setAll(k,0,0); break;
case 1: setAll(0,k,0); break;
case 2: setAll(0,0,k); break;
}
showStrip();
delay(3);
}
// Fade OUT
for(int k = 255; k >= 0; k--) {
switch(j) {
case 0: setAll(k,0,0); break;
case 1: setAll(0,k,0); break;
case 2: setAll(0,0,k); break;
}
showStrip();
if (readstatus()!=auswahl) return;
delay(3);
}
}
}
void TwinkleRandom(int auswahl, int Count, int SpeedDelay, boolean OnlyOne) {
setAll(0,0,0);
dimin(1);
while (1)
{
for (int i=0; i<Count; i++) {
setPixel(random(NUM_LEDS),random(0,255),random(0,255),random(0,255));
showStrip();
if (readstatus()!=auswahl) return;
delay(SpeedDelay);
if(OnlyOne) {
setAll(0,0,0);
}
}
if (readstatus()!=auswahl) return;
delay(SpeedDelay);
dimout(5);
setAll(0,0,0);
dimin(1);
}
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
}
void showStrip() {
FastLED.show();
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
FastLED.show();
}
void setCockpit(byte red, byte green, byte blue) {
for(int i = 90; i < 92; i++ ) {
setPixel(i, red, green, blue);
}
FastLED.show();
}
void setAntrieb(byte red, byte green, byte blue) {
for(int i = 92; i < 101; i++ ) {
setPixel(i, red, green, blue);
}
FastLED.show();
}
void setAllRing (byte red, byte green, byte blue)
{
int i;
for (i=0;i<=5;i++)
{
setRing(i,red,green,blue);
}
}
void setRing (byte nummer, byte red, byte green, byte blue)
{
for(int i = 0; i < 15; i++ ) {
setPixel(((nummer)+(i*6)), red, green, blue);
}
FastLED.show();
}