//Simple (working) led fade programm for analog resistor input + adjustable stroposcop function by marderchen MEOW =^.^= #define prot PA0 #define pgrun PA1 #define pblau PA2 #define pw6 PA3 #define pw2 PA4 #define rotlinks PA5 #define tlinks PA6 #define tmitte PA7 #define w6 PB11 //PA8 #define trechts PB0 #define rotrechts PB1 #define fan PB5 #define b10 PB10 #define rot PB12 #define grun PB13 #define blau PB14 #define w2 PB15 int rrot =0; int rgrun =0; int rblau =0; int rw2 =0; int rw6 =0; long allfcount = micros(); long stropos = micros(); int duty1 =0; int duty2 =0; int duty3 =0; int duty4 =0; int duty5 =0; int duty6 =0; int duty7 =0; int duty8 =0; int kuhl =0; int zahl =0; int zahl2 =0; int zahl3 =0; int kuhlbl =0; int fcount1 =0; int fcount2 =0; int stropoc =0; int sl =0; int chaost =0; void setup() { pinMode(w2, OUTPUT); pinMode(w6, OUTPUT); pinMode(rot, OUTPUT); pinMode(grun, OUTPUT); pinMode(blau, OUTPUT); pinMode(rotlinks, OUTPUT); pinMode(rotrechts, OUTPUT); pinMode(fan, OUTPUT); pinMode(tlinks, INPUT); pinMode(tmitte, INPUT); pinMode(trechts, INPUT); } void loop() { sl++; if (sl >= 700) { if ((analogRead(prot) /10) >= rrot && rrot <=398) { rrot +=1;} if ((analogRead(pgrun) /10) >= rgrun && rgrun <=398) { rgrun +=1;} if ((analogRead(pblau) /10) >= rblau && rblau <=398) { rblau +=1;} if ((analogRead(pw2) /10) >= rw2 && rw2 <=398) { rw2 +=1;} if ((analogRead(pw6) /10) >= rw6 && rw6 <=398) { rw6 +=1;} if ((analogRead(prot) /10) <= rrot && rrot >=0) { rrot -=1;} if ((analogRead(pgrun) /10) <= rgrun && rgrun >=0) { rgrun -=1;} if ((analogRead(pblau) /10) <= rblau && rblau >=0) { rblau -=1;} if ((analogRead(pw2) /10) <= rw2 && rw2 >=0) { rw2 -=1;} if ((analogRead(pw6) /10) <= rw6 && rw6 >=0) { rw6 -=1;} sl=0;} if (digitalRead(trechts) == HIGH && zahl2 ==0) { zahl2 =1; } if (zahl2 == 1) { zahl3++;} if (zahl3 == 2) { stropoc++;} if (zahl3 >= 9000) { zahl3 =0; zahl2=0;} if (stropoc ==1) {stropo();} if (stropoc ==2) {chaos();} if (stropoc ==3) {stropoc =0; duty7=410;} dimmlicht(); puste(); machlicht(); } void chaos(void){ chaost++; if (chaost >= random(100,4000)){duty1= random(0,420); duty2= random(0,420); duty3= random(0,420); duty4= random(0,420); duty5= random(0,420); duty6= random(0,420); duty7= random(0,420);} chaost =0;} void stropo(void) { duty7 += random(1,20); if (duty7 >= 398) {duty7=0;} while ((micros()-stropos) >= 80) { fcount2++; if (fcount2 == (rw6 )) { digitalWrite(rot, HIGH ); digitalWrite(grun, HIGH ); digitalWrite(blau, HIGH ); digitalWrite(w2, HIGH ); } if (fcount2 >= (rw6 *1.07)) { digitalWrite(rot, LOW ); digitalWrite(grun, LOW ); digitalWrite(blau, LOW ); digitalWrite(w2, LOW ); digitalWrite(w6, LOW ); fcount2 = 0; } stropos = micros(); } } void puste(void) { kuhlbl ++; if (digitalRead(tlinks) == HIGH) { zahl++;} if (zahl >= 100) { zahl =0;} if (zahl == 1) { kuhl +=10;} if (kuhl >= 170) {kuhl =0;} if (kuhl <= 150 && kuhlbl <= (kuhl*10)) {duty8 = kuhl; duty6 = kuhl; } if (kuhl >= 151 && kuhlbl <= (kuhl*10)) {duty8 = rw6; duty6 = rw6;} if (kuhlbl == (kuhl*10)) {duty6 = 150;} if (kuhlbl >= (kuhl*11)) {kuhlbl=0;} } void dimmlicht(void) { if (rrot <= 398) {duty1 = rrot; } if (rrot >= 399) {duty1 = 400; } if (rgrun <= 398) {duty2 = rgrun; } if (rgrun >= 399) {duty2 = 400; } if (rblau <= 398) {duty3 = rblau; } if (rblau >= 399) {duty3 = 400; } if (rw2 <= 398) {duty4 = rw2; } if (rw2 >= 399) {duty4 = 400; } if (rw6 <= 398) {duty5 = rw6; } if (rw6 >= 399) {duty5 = 400; } } void machlicht(void) { while ((micros()-allfcount) >= 20) { fcount1++; if (stropoc ==0 | stropoc ==2){ if (fcount1 == (400-duty1)) { digitalWrite(rot, HIGH );} if (fcount1 == (400-duty2)) { digitalWrite(grun, HIGH );} if (fcount1 == (400-duty3)) { digitalWrite(blau, HIGH );} if (fcount1 == (400-duty4)) { digitalWrite(w2, HIGH );} if (fcount1 == (400-duty5)) { digitalWrite(w6, HIGH );} } if (fcount1 == (400-duty6)) { digitalWrite(rotlinks, HIGH );} if (fcount1 == (400-duty7)) { digitalWrite(rotrechts, HIGH );} if (fcount1 == (400-duty8)) { digitalWrite(fan, HIGH );} if (fcount1 >= 410 ) { if (stropoc ==0){ digitalWrite(rot, LOW ); digitalWrite(grun, LOW ); digitalWrite(blau, LOW ); digitalWrite(w2, LOW ); digitalWrite(w6, LOW ); } digitalWrite(rotlinks, LOW ); digitalWrite(rotrechts, LOW ); digitalWrite(fan, LOW ); fcount1 = 0; } allfcount = micros(); } }