//marten Kote for cactus home build new sunn(optical sensor)/time controled full spectrum (white(4x3Watt),UV (2x3Watt),white (1x100Watt),RGB (3x3Watt) (also temperatureassure for supply and heatsinks and speedcontroled fan) thingy //basicly cactus 2pcs inside, but iam MEOW so orderet nepeta cataria seeds, saused more usefull than cactus, and can mak nice health tea with it.. also good for try growpower of leds.. //also build in 8x MAXdig led modul, and 4dasters, 2x STRAW head interface LEDs, new case, etc.. //its free do with it or parts whatever you want.. if its usefull.. //MEOW have fun #include #include #include const byte chips = 1; // 1 chip, bit banged SPI on pins 6, 7, 8 MAX7219 display (chips, PA4, PA7, PA5); // Chips / LOAD / DIN / CLK String outzi = "Purrrrrr "; #define rot1 PC15 #define grun1 PC14 #define blau1 PC13 #define white2 PB0 #define white3 PB1 #define blaux1 PB10 #define blaux2 PB11 #define white PB9 #define UV PB8 #define fan PB7 #define t1 PA12 #define t2 PA15 #define t3 PB6 #define t4 PB5 #define rot1f PB12 #define grun1f PB13 #define blau1f PB14 #define rot2f PB15 #define grun2f PA8 #define blau2f PA9 #define temp1 PA1 #define temp2 PA2 #define LDR PA0 #define KA PA3 uint8_t onpress[10]; int16_t duty[14]; uint8_t zeit[22][2]; int power=10; int progy=0; long maintime=millis(); long maintime2=micros(); long runtime=0; long fadetime=79200; int zeit1,zeit2,zeit3,zeit4,zeit5,zeit6; uint16_t sonne,trafo,heatsink; boolean tplusset=false; boolean tminusset=false; boolean tnenset=false; boolean saver =false; int16_t rainbow; int16_t bright =300; int ani=0; int fansens=46; int manual=0; String adzi=""; void setup() { pinMode(rot1, OUTPUT); pinMode(grun1, OUTPUT); pinMode(blau1, OUTPUT); pinMode(UV, OUTPUT); pinMode(fan, OUTPUT); pinMode(white, OUTPUT); pinMode(white2, OUTPUT); pinMode(white3, OUTPUT); pinMode(blaux1, OUTPUT); pinMode(blaux2, OUTPUT); pinMode(rot1f, OUTPUT); pinMode(grun1f, OUTPUT); pinMode(blau1f, OUTPUT); pinMode(rot2f, OUTPUT); pinMode(grun2f, OUTPUT); pinMode(blau2f, OUTPUT); pinMode(t1, INPUT); pinMode(t2, INPUT); pinMode(t3 ,INPUT); pinMode(t4 ,INPUT); delay(1300); display.begin (); zeigwortUzahl("boot",1234); delay(300); } void loop() { istinput(); zeitreise(); rainbowcalc(); machlicht(); if (progy == 0) {zeigwortUzahl("Sun_",sonne); fadefarben(progy,5,10);} if (progy == 1) {zeigwortUzahl("Core",trafo); fadefarben(progy,6,10);} if (progy == 2) {zeigwortUzahl("Alu_",heatsink); fadefarben(progy,7,10);} if (progy == 3) {zeigwortUzahl("uite",duty[4]); fadefarben(progy,8,10); //stelltweis 100W if (tplusset ==true) {tplusset=false; duty[4]+=5; if (duty[4] >400) {duty[4]=800;}} if (tminusset ==true) {tminusset=false; duty[4]-=5;} } if (progy == 4) {zeigwortUzahl("Uu__",duty[3]); fadefarben(progy,9,10); // stellt UV 2x 3Watt if (tplusset ==true) {tplusset=false; duty[3]+=20; if (duty[3] >800) {duty[3]=800;}} if (tminusset ==true) {tminusset=false; duty[3]-=20;} } if (progy == 5) {if (runtime%2==0) {zeigwortUzahl("Fan_",fansens);}if (runtime%2==1) {zeigwortUzahl("Fan_",duty[11]);} fadefarben(progy,10,10); //zeigt lüfterpower } if (progy == 6) {zeigwortUzahl("uu2_",duty[12]); fadefarben(progy,5,10); fadefarben(progy,8,10); //stelltweis 4x 3W if (tplusset ==true) {tplusset=false; duty[12]+=20; if (duty[12] >800) {duty[12]=800;}} if (tminusset ==true) {tminusset=false; duty[12]-=20;} } if (progy == 7) {zeigwortUzahl("blau",duty[13 ]);fadefarben(progy,6,10); fadefarben(progy,9,10); //stellt 4x blau 3watt if (tplusset ==true) {tplusset=false; duty[13]+=20; if (duty[13] >800) {duty[13]=800;}} if (tminusset ==true) {tminusset=false; duty[13]-=20;} } if (progy == 8) {zeigwortUzahl("rain",rainbow); fadefarben(progy,7,10); fadefarben(progy,10,10);// stellt regenbogenfarbe if (tplusset ==true) {tplusset=false; rainbow+=100; } if (tminusset ==true) {tminusset=false; rainbow-=20;} } if (progy == 9) {zeigwortUzahl("brig",bright); fadefarben(progy,8,10); fadefarben(progy,9,10); if (tplusset ==true) {tplusset=false; bright+=20; if (bright >800) {bright=800;}} if (tminusset ==true) {tminusset=false; bright-=20;} } if (progy == 10) {zeigwortUzahl("Uhr",runtime);} //sekundenuhrzeit if (progy == 11) {fadefarben(progy,8,10); fadefarben(progy,9,10); fadefarben(progy,10,10); //istzeit if (tnenset ==true) {tnenset=false; runtime+=3600;} if (tplusset ==true) {tplusset=false; runtime+=120;} if (tminusset ==true) {tminusset=false; runtime-=60;} } if (progy == 12) {if (manual ==1) {zeigwortUzahl("auto",manual);} if (manual==0) { zeigwortUzahl("set",manual); } fadefarben(progy,5,10); fadefarben(progy,9,5); fadefarben(progy,7,2); //äbndert fadeautomatic manuell if (tnenset ==true) {tnenset=false; manual++; if (manual >=2) {manual=0;}} } if (progy == 13) {zeigwortUzahl("off",fadetime); zeigzeit(fadetime); //stellfadezeuit nacht if (tnenset ==true) {tnenset=false; fadetime+=3600;} if (tplusset ==true) {tplusset=false; fadetime+=120;} if (tminusset ==true) {tminusset=false; fadetime-=60;}} if (progy == 14) {} if (progy == 15) {progy=0;} } void fadefarben(int progy,int welcheden,int spedies){ // 5rot,6grun,7blau8rot2,9grun2,10blau2 if (zeit[progy][0] >spedies) {zeit2=0; if (duty[welcheden] >= 799) {zeit[progy][1]=1; } if (duty[welcheden] <= 0) {zeit[progy][1]=0; } if (zeit[progy][1]==0 ) {duty[welcheden]+=2;} if (zeit[progy][1]==1 ) {duty[welcheden]--;} for (int dienicht =5; dienicht <10; dienicht++) {if (dienicht != welcheden || duty[dienicht] >=1) {duty[dienicht]--;}} }} void lesesensibel(){ if ((analogRead(LDR)/5) >= sonne) { sonne++;} if ((analogRead(LDR)/5) < sonne) { sonne--;} if ((analogRead(temp2)/5) >= trafo) { trafo++;} if ((analogRead(temp2)/5) < trafo) { trafo--;} if ((analogRead(temp1)/5) >= heatsink) { heatsink++;} if ((analogRead(temp1)/5) < heatsink) { heatsink--;} if (heatsink <500 && trafo <490) {duty[11]=round((heatsink-330)*(fansens/10));} else {duty[11]=800;}//core+slu 330 kalt, alu 500 hot core } void istinput(void){ if (zeit1 >=1) { if (digitalRead(t1) == HIGH && onpress[0] ==0) { onpress[0] =1; progy++;} if (onpress[0] == 1) { onpress[1]++; } if (onpress[1] >= 20) { onpress[1] =0; onpress[0]=0; } if (digitalRead(t2) == HIGH && onpress[2] ==0) { onpress[2] =1; tnenset=true; } if (onpress[2] == 1) { onpress[3]++;} if (onpress[3] >= 20) { onpress[3] =0; onpress[2]=0; } if (digitalRead(t3) == HIGH && onpress[4] ==0) { onpress[4] =1; tplusset=true; } if (onpress[4] == 1) { onpress[5]++;} if (onpress[5] >= 10) { onpress[5] =0; onpress[4]=0; } if (digitalRead(t4) == HIGH && onpress[6] ==0) { onpress[6] =1; tminusset=true; } if (onpress[6] == 1) { onpress[7]++;} if (onpress[7] >= 10) { onpress[7] =0; onpress[6]=0; } if (onpress[1] >1 || onpress[3] >1 || onpress[5] >1 || onpress[7] >1) { duty[6]=400;} if (duty[6] > 10) {duty[6]-=10;} zeit1=0; }} long timez= millis(); void zeitreise(void){ while ((millis()- maintime) >= 10) { zeit1++; lesesensibel(); maintime = millis(); } while ((micros()- maintime2) >= 400) { for (int pragy =0; pragy <20; pragy++){if (zeit[pragy][0]< 200) {zeit[pragy][0]++;}} maintime2 = micros(); } while ((millis()- timez) >= 980) { runtime++; if (runtime >=86400) {runtime=0;} if (progy==11) {zeigzeit(runtime);} timez = millis(); } } void rainbowcalc(void) { if(rainbow >=0 && rainbow <=400) {duty[0] =400; duty[1] =rainbow; duty[2] =0;} //rot ->gelb (rotmax grün+ blau0) if(rainbow >=401 && rainbow <=801) {duty[0] =(400 -(rainbow -401)); duty[1] =400; duty[2] =0;} //gelb ->grün (rot- grünmax blau0) if(rainbow >=802 && rainbow <=1202) {duty[0] =0; duty[1] =400; duty[2] =(rainbow - 802);} //grün ->cyan (rot0 grünmax blau+) if(rainbow >=1203 && rainbow <=1603) {duty[0] =0; duty[1] =(400 -(rainbow - 1203)); duty[2] =400;} //cyan ->blau (rot0 grün- blaumax) if(rainbow >=1604 && rainbow <=2004) {duty[0] =(rainbow-1604); duty[1] =0; duty[2] =400;} //blau ->lila (rot+ grün0 blaumax) if(rainbow >=2005 && rainbow <=2405) {duty[0] =400; duty[1] =0; duty[2] =(400- (rainbow -2006));} //lila ->rot (rotmax grün0 blau-) if(rainbow >= 2406) {rainbow =0;} } void zeigwortUzahl(String wortzz,int zahlzz){ zeigwort(wortzz); zeigzahl(zahlzz); } void zeigzahl(int zahlz) { outzi=""; if(zahlz <=9) {outzi+="0";} if(zahlz <=99) {outzi+="0";} if(zahlz <=999) {outzi+="0";} outzi+=String(zahlz); for (byte ixx = 0; ixx < 4; ixx++){display.sendChar (ixx+4, outzi[ixx]);}} void zeigwort(String woortz) { for (int iqq = 0; iqq < 4; iqq++){display.sendChar (iqq, woortz[iqq]);}} void undlos(String meows) { // for print string to MAX 8dig display for (int i = 0; i < 8; i++){ display.sendChar (i, meows[i]); } } void zeigzeit(long itstime) { outzi=""; ani++; adzi=""; if (ani>=4) {ani=0;} if (ani==0) {adzi+="u";}if (ani==1) {adzi+="_";} if (ani==2) {adzi+="n";} if (ani==3) {adzi+="-";} if (((itstime/60/60)%60) <=9){outzi+="0";} outzi+=String(((itstime/60)/60)%60); outzi+=adzi; if (((itstime/60)%60) <=9){outzi+="0";} outzi+=String((itstime/60)%60); outzi+=adzi; if ((itstime%60) <=9){outzi+="0";} outzi+=String(itstime%60); for (byte jxx = 0; jxx < 8; jxx++){display.sendChar (jxx, outzi[jxx]);}} long startriger=micros(); long sunriger=micros(); uint16_t light,darkness,dcach; void machlicht(void) { if (bright > 400){light=bright-400; darkness=0;} if (bright <=400){darkness=(400-(bright)); light=0;} while ((micros()-sunriger) >= 20) { for (int16_t fcount2=2; fcount2 <(401); fcount2++) { if (fcount2 == ((400)-duty[4])) { digitalWrite(white, HIGH );} if (fcount2 >= 399) { digitalWrite(white, LOW );}}sunriger= micros(); } while ((micros()-startriger) >= 2) { for (int16_t fcount1=0; fcount1 <(802); fcount1++) { if (fcount1 == ((401+darkness)-duty[0])) { digitalWrite(rot1, HIGH );} if (fcount1 == ((401+darkness)-duty[1])) { digitalWrite(grun1, HIGH );} if (fcount1 == ((401+darkness)-duty[2])) { digitalWrite(blau1, HIGH );} if (fcount1 == ((801)-duty[3])) { digitalWrite(UV, HIGH );} if (fcount1 == (duty[4])) { digitalWrite(white, LOW );} if (fcount1 == ((801)-duty[5])) { digitalWrite(rot1f, HIGH );} if (fcount1 == ((801)-duty[6])) { digitalWrite(grun1f, HIGH );} if (fcount1 == ((801)-duty[7])) { digitalWrite(blau1f, HIGH );} if (fcount1 == ((801)-duty[8])) { digitalWrite(rot2f, HIGH );} if (fcount1 == ((801)-duty[9])) { digitalWrite(grun2f, HIGH );} if (fcount1 == ((801)-duty[10])) { digitalWrite(blau2f, HIGH );} if (fcount1 == ((801)-duty[11])) { digitalWrite(fan, HIGH );} if (fcount1 == ((801)-duty[12])) { digitalWrite(white2, HIGH ); digitalWrite(white3, HIGH ); } if (fcount1 == ((801)-duty[13])) { digitalWrite(blaux1, HIGH );digitalWrite(blaux2, HIGH );} if (fcount1 >= (402 + light) ) { digitalWrite(rot1, LOW ); digitalWrite(grun1, LOW ); digitalWrite(blau1, LOW );} if (fcount1 >= 800) { digitalWrite(rot1f, LOW ); digitalWrite(grun1f, LOW ); digitalWrite(blau1f, LOW ); digitalWrite(rot2f, LOW ); digitalWrite(grun2f, LOW ); digitalWrite(blau2f, LOW ); digitalWrite(UV, LOW );digitalWrite(fan, LOW ); digitalWrite(white2, LOW ); digitalWrite(white3, LOW ); digitalWrite(blaux1, LOW ); digitalWrite(blaux2, LOW ); }} startriger = micros();}}