//Simple programm RGB fire imitating HIGH power led device //\/ pindefinitionen/belegung #define rot PB13 //2x3Watt RGB A #define grun PB14 //2x3Watt RGB A #define blau PB12 //2x3Watt RGB A #define rot1 PA8 //2x3Watt RGB B #define grun1 PB11 //2x3Watt RGB B #define blau1 PB15 //2x3Watt RGB B #define rotp PB10 //ultrahelle 28mAh rote LED an seite #define poti PA7 //drehknopf //\/zwischenspeicherwerte int duty[10]; long allfcount = micros(); long maintime = millis(); int RGB =0; int light =400; int lights =0; int darkness =0; int zufall[8][4]; int fcount1 =0; int fcount2 =0; int zeit1 =0; int zeit2 =0; int zeit3 =0; int zeit4 =0; int zeit5 =0; int zeit6 =0; int stasi =0; int mainspeed=20; int oftblitz=5; //0kein, 1000nur) int difid =200; int modus=0; boolean wusch=false; void setup() { pinMode(rot, OUTPUT); pinMode(grun, OUTPUT); pinMode(blau, OUTPUT); pinMode(rot1, OUTPUT); pinMode(grun1, OUTPUT); pinMode(blau1, OUTPUT); } void loop() { wenntaster(); nottohigh(); purrpower(); machlicht(); } void wenntaster(void){ //drehknopfbetätigung if (zeit5 > 500) { if (modus==1 && RGB < (analogRead(poti)/1.5+200) ) {RGB+=8; } if (modus==1 && RGB > (analogRead(poti)/1.5+200) ) {RGB-=8; } if (analogRead(poti) < 100 && !wusch) {wusch =true; modus++;} zeit5=0;} if (modus ==0) {wuselzufall(); stasi=399;} if (modus ==1) { lights =500; stasi=100; rgbcalc();} if (modus ==2 && zeit1 > 10 ) {RGB+=analogRead(poti)/30 -10; stasi=20; lights =500; zeit1 =0; rgbcalc(); } if (modus ==3) {modus =0;} if (zeit2 > 350) {wusch =false, zeit2 =0; } } void wuselzufall(void){ //feuer simulation if (zeit3 > (zufall[0][0]/10+200)) { //zeitgeber zufall[0][0] = random(zufall[0][2],zufall[0][3]); //basisinterfall zufall[0][2] = random(mainspeed,mainspeed+300); //minimalgrenze zufall[0][3] = random(zufall[0][2],mainspeed+640); //maximalgrenze zufall[1][0] = random(zufall[1][1],zufall[1][2]); //pegelhelligkeit zufall[1][1] = random(zufall[1][3]-100,zufall[1][3]+50); zufall[1][2] = random(zufall[1][3]+50,zufall[1][3]+120); zufall[1][3] = random(analogRead(poti)/20,analogRead(poti)/20+190); //helligkeit zufall[2][0] =random(0,10); zeit3=0; } if (zeit4 > (zufall[0][3]/2)){ //feueer //vorne if (duty[3] > zufall[1][0] && duty[3] > (zufall[1][3]+50) ) { zufall[4][0]=0; } //rot if (duty[3] < zufall[1][0] && duty[3] < 5 ) { zufall[4][0]=1;} //rot if (duty[4] > (zufall[1][3]-150)&& duty[4] > (zufall[1][2]-150)) { zufall[4][1]=0;} //grun if (duty[4] < (zufall[1][3]-100)&& duty[4] < 5 ) { zufall[4][1]=1;} //grun if (duty[5] > (zufall[1][3]-330)&& duty[5] > (zufall[1][3]-300)) { zufall[4][2]=0;} //blau if (duty[5] < (zufall[1][3]-300)&& duty[5] < 7 ) { zufall[4][2]=1;} //blau //vorne if (duty[0] > zufall[1][0] && duty[0] > (zufall[1][3]+50) ) { zufall[5][0]=0; } //rot if (duty[0] < zufall[1][0] && duty[0] < 5 ) { zufall[5][0]=1;} //rot if (duty[1] > (zufall[1][3]-150)&& duty[1] > (zufall[1][2]-150)) { zufall[5][1]=0;} //grun if (duty[1] < (zufall[1][3]-100)&& duty[1] < 5 ) { zufall[5][1]=1;} //grun if (duty[2] > (zufall[1][3]-330)&& duty[2] > (zufall[1][3]-300)) { zufall[5][2]=0;} //blau if (duty[2] < (zufall[1][3]-300)&& duty[2] < 7 ) { zufall[5][2]=1;} //blau if (zufall[4][0] == 0) {duty[3]--;} if (zufall[4][0] == 1) {duty[3]+=2;} if (zufall[4][1] == 0) {duty[4]-=2;} if (zufall[4][1] == 1) {duty[4]+=2;} if (zufall[4][2] == 0) {duty[5]--;} if (zufall[4][2] == 1) {duty[5]++;} if (zufall[5][0] == 0) {duty[0]-=random(1,8);} if (zufall[5][0] == 1) {duty[0]+=random(1,8);} if (zufall[5][1] == 0) {duty[1]-=random(1,8);} if (zufall[5][1] == 1) {duty[1]+=random(1,8);} if (zufall[5][2] == 0) {duty[2]+=random(1,8);} if (zufall[5][2] == 1) {duty[2]+=random(1,8);} // if (zufall[2][0] >5) {duty[0] = duty[3]; duty[1] = duty[4]; duty[2] = duty[5]; } zeit4=0; } } void purrpower(void){ //updownfaden der roten led an seite if (zeit6 >(600-stasi/2)) { if(zufall[2][1] == 1) {duty[6]++;} if(zufall[2][1] == 0) {duty[6]--;} if(duty[6] > stasi) {zufall[2][1]=0;} if(duty[6] < 1) {zufall[2][1]=1;} zeit6=0; } } void nottohigh(void){ //nicht zwingend nötig if (zeit1 > 1000) {zeit1=0;} if (zeit2 > 1000) {zeit2=0;} if (zeit3 > 1000) {zeit3=0;} if (zeit4 > 1000) {zeit4=0;} if (zeit5 > 1000) {zeit5=0;} if (zeit6 > 1000) {zeit6=0;} } void rgbcalc(void) { //berechnet farben if (light >= 400) {darkness =0; lights = light -400;} if (light <= 399) {darkness =399 -light; lights =0;} if(RGB >=0 && RGB <=400) {duty[0] =400 -darkness; duty[1] =RGB + lights; duty[2] =0 + lights;} //rot ->gelb (rotmax grün+ blau0) if(RGB >=401 && RGB <=801) {duty[0] =(400 -(RGB -401)) +lights; duty[1] =400 -darkness; duty[2] =0 +lights;} //gelb ->grün (rot- grünmax blau0) if(RGB >=802 && RGB <=1202) {duty[0] =0+lights; duty[1] =400 -darkness; duty[2] =(RGB - 802) + lights;} //grün ->cyan (rot0 grünmax blau+) if(RGB >=1203 && RGB <=1603) {duty[0] =0+lights; duty[1] =(400 -(RGB - 1203)) +lights; duty[2] =400 -darkness;} //cyan ->blau (rot0 grün- blaumax) if(RGB >=1604 && RGB <=2004) {duty[0] =(RGB-1604) +lights; duty[1] =0 +lights; duty[2] =400 -darkness;} //blau ->lila (rot+ grün0 blaumax) if(RGB >=2005 && RGB <=2405) {duty[0] =400 -darkness; duty[1] =0+lights; duty[2] =(400- (RGB -2006)) +lights;} //lila ->rot (rotmax grün0 blau-) if(RGB >= 2406) {RGB =0;} duty[3]=duty[0]; duty[4]=duty[1]; duty[5]=duty[2]; } void machlicht(void) { //schaltet leds while ((micros()-allfcount) >= 3) { fcount1++; if (fcount1 == (401-duty[0])) { digitalWrite(rot, HIGH );} if (fcount1 == (401-duty[1])) { digitalWrite(grun, HIGH );} if (fcount1 == (401-duty[2])) { digitalWrite(blau, HIGH );} if (fcount1 == (401-duty[3])) { digitalWrite(rot1, HIGH );} if (fcount1 == (401-duty[4])) { digitalWrite(grun1, HIGH );} if (fcount1 == (401-duty[5])) { digitalWrite(blau1, HIGH );} if (fcount1 == (401-duty[6])) { digitalWrite(rotp, HIGH );} if (fcount1 >= 410 ) { digitalWrite(rot, LOW ); digitalWrite(grun, LOW ); digitalWrite(blau, LOW ); digitalWrite(rot1, LOW ); digitalWrite(grun1, LOW ); digitalWrite(blau1, LOW ); digitalWrite(rotp, LOW ); fcount1 = 0; zeit1++; zeit2++; } zeit5++; zeit4++;zeit3++; zeit6++; allfcount = micros(); } } /*It's marderchens code mess and FREEEEE use it or parts if you want! * * ___ __ ___ ______ ____ _ __ ___ / _/ / |/ / / ____/ / __ \| | / / / / / / / /|_/ / / __/ / / / /| | /| / / / / / / / / / / / /___ / /_/ / | |/ |/ / / / / / /_/ /_/ /_____/ \____/ |__/|__/ _/ / /__/ /__/ ___ //| / _ \ |/|| _____ / // / /____/ _ _ _ \___/ _ /____/ ( )( )( ) (_) |/ |/ |/ */