#define rot PC13 #define grun PC14 #define blau PC15 #define MOSI PA0 #define mess1 PA1 #define mess2 PA2 #define mess3 PB0 #define mess3 PA3 #define mess4 PB9 #define mess5 PB8 #define t1 PB12 #define t2 PB13 #define t3 PB14 #define t4 PA12 #define t5 PA15 #include #include #include const byte chips = 1; MAX7219 display (chips, PA4, PA7, PA5); // Chips / LOAD / DIN / CLK uint8_t onpress[15],zeit1; uint16_t temps[5],offtimecount; uint16_t errortemp=1000; uint32_t offtime=500; uint16_t laag=100; uint16_t daszeugs=0; long maintime=millis(); long maintime2=millis(); long maintime3=micros(); long timez= millis(); long mosipulsi=micros(); boolean onk=false; boolean alarmeld=false; boolean tplusset=false; boolean tminusset=false; String outzi=""; void setup() { delay(200); pinMode(rot, OUTPUT); pinMode(grun, OUTPUT); pinMode(blau, OUTPUT);pinMode(MOSI, OUTPUT); pinMode(t1, INPUT); pinMode(t2, INPUT); pinMode(t3 ,INPUT); pinMode(t4 ,INPUT); pinMode(t5 ,INPUT); delay(300); display.begin (); undlos("boot",0); delay(300); } void loop() { istinput(); zeitreise(); //if (onk==true) {digitalWrite(grun,HIGH);}else {digitalWrite(grun,LOW);} } uint16_t offtimestep =100; void funktionsmodis(uint8_t denda) { if(denda==0) { if (tplusset ==true && (offtime+offtimestep) <9999) {tplusset=false; offtime+=offtimestep;} if (tminusset ==true && offtime >10) {tminusset=false; offtime-=10; }} if(denda==1) { if (tplusset ==true && (laag+1) < 800) {tplusset=false; laag++;} if (tminusset ==true && laag >0) {tminusset=false; laag--;} }} void SPAM(){ if (daszeugs==0) {zeigwort("fast",1); zeigzahl(offtime,2); } if (daszeugs==1) {zeigwort("laag",1); zeigzahl(laag,2); } if (daszeugs==2) {zeigwort("PA1_",1); zeigzahl(temps[0],2);} if (daszeugs==3) {zeigwort("PA2_",1); zeigzahl(temps[1],2);} if (daszeugs==4) {zeigwort("PA3",1); zeigzahl(temps[2],2);} if (daszeugs==5) {zeigwort("PB1",1); zeigzahl(temps[3],2);} if (daszeugs==6) {zeigwort("PB0",1); zeigzahl(temps[4],2);} if (daszeugs==7) {zeigwort("eror",1); zeigzahl(errortemp,2);} if (daszeugs>=8) {daszeugs=0;} } long cachz=0; void lesesensibel(){ if ((analogRead(mess1)/4) > temps[0]) {temps[0]+=1; } if ((analogRead(mess1)/4) < temps[0]) {temps[0]-=1; } if ((analogRead(mess2)/4) > temps[1]) {temps[1]+=1; } if ((analogRead(mess2)/4) < temps[1]) {temps[1]-=1; } if ((analogRead(mess3)/4) > temps[2]) {temps[2]+=1; } if ((analogRead(mess3)/4) < temps[2]) {temps[2]-=1; } if ((analogRead(mess4)/4) > temps[3]) {temps[3]+=1; } if ((analogRead(mess4)/4) < temps[3]) {temps[3]-=1; } if ((analogRead(mess5)/4) > temps[4]) {temps[4]+=1; } if ((analogRead(mess5)/4) < temps[4]) {temps[4]-=1; } for (uint8_t leseall=0; leseall <4; leseall++) {if (temps[leseall] > errortemp) {onk=false; alarmeld=true;} else {alarmeld=false;}} } void schaltmal(boolean anaus){ if (anaus==true) {if (onk==true) {onk=false; return;}else {onk=true; return;}} if (anaus==false){onk=true;}} void istinput(void){ if (zeit1 >=5) { if (digitalRead(t1) == HIGH && onpress[0] ==0) { onpress[0] =1; tplusset=true; } if (onpress[0] == 1) { onpress[1]++; } if (onpress[1] >= 5) { onpress[1] =0; onpress[0]=0; } if (digitalRead(t2) == HIGH && onpress[2] ==0) { onpress[2] =1; daszeugs++;} if (onpress[2] == 1) { onpress[3]++; } if (onpress[3] >= 10) { onpress[3] =0; onpress[2]=0; } if (digitalRead(t3) == HIGH && onpress[4] ==0) { onpress[4] =1; schaltmal(true); } if (onpress[4] == 1) { onpress[5]++; } if (onpress[5] >= 20) { onpress[5] =0; onpress[4]=0; } if (digitalRead(t4) == HIGH && onpress[6] ==0) { onpress[6] =1; onk=false;} if (onpress[6] == 1) { onpress[7]++; } if (onpress[7] >= 6) { onpress[7] =0; onpress[6]=0; } if (digitalRead(t5) == HIGH && onpress[8] ==0) { onpress[8] =1; tminusset=true; } if (onpress[8] == 1) { onpress[9]++; } if (onpress[9] >= 5) { onpress[9] =0; onpress[8]=0; } SPAM(); zeit1=0;}} void zeitreise(void){ while ((millis()- maintime) >= 5){zeit1++; maintime = millis();} while ((micros()- maintime3) >= 60) {lesesensibel(); maintime3 = micros();} while ((millis()- maintime2) >= 6) {funktionsmodis(daszeugs); maintime2 = millis();} while ((millis()- timez) >= 998) {SPAM();timez = millis();} while ((micros()-mosipulsi) >= 2) {offtimecount++; habnenfehlerleucht(); if(offtimecount >offtime) {offtimecount=0; if (onk==true) {pulspower();}} digitalWrite(blau,LOW); digitalWrite(MOSI,LOW); mosipulsi = micros(); }} void pulspower() {for (int16_t fcount=0; fcount <(802); fcount++) { if (fcount==0) {digitalWrite(MOSI, LOW); digitalWrite(blau, LOW);} if (fcount==1) {digitalWrite(MOSI, HIGH); digitalWrite(blau, HIGH);} if (fcount>=(laag+1)){digitalWrite(MOSI, LOW); digitalWrite(blau, LOW);} }} uint16_t alarmc1,alarmc2,alarmc3; void habnenfehlerleucht(void) { if (alarmeld==true) { if (alarmc1 >0) {alarmc1--;} if (alarmc1 <=0) {alarmc1=500;} alarmc2++; if (alarmc2 > alarmc1) {alarmc3++; if ((alarmc3%2)==0) {digitalWrite(rot,HIGH);} if (alarmc3 >10) {digitalWrite(grun,HIGH); alarmc3=0;}} if (alarmc2 > (alarmc1+round(alarmc1/25))) {alarmc2=0;digitalWrite(rot,LOW);digitalWrite(grun,LOW);} else{digitalWrite(rot,LOW);digitalWrite(grun,LOW); } }} void zeigwortuzahl(String texte, int werty){zeigwort(texte,1);zeigzahl(werty,2);} void zeigzahl(int zahlz,int daa) { outzi=""; if(zahlz <=9) {outzi+="0";} if(zahlz <=99) {outzi+="0";} if(zahlz <=999) {outzi+="0";} outzi+=String(zahlz); if (daa ==1) {for (byte ixx = 0; ixx < 4; ixx++){display.sendChar (ixx, outzi[ixx]);}} if (daa ==2) {for (byte ix2 = 0; ix2 < 4; ix2++){display.sendChar (ix2+4, outzi[ix2]);}}zahlz=0;} void zeigwort(String woortz,int hier) { if (hier == 1){for (int iqq = 0; iqq < 4; iqq++){display.sendChar (iqq, woortz[iqq]);}} if (hier == 2){for (int iq2 = 0; iq2 < 4; iq2++){display.sendChar (iq2+4, woortz[iq2]);}} woortz="";} void undlos(String meows,uint8_t dasss) { // for print string to MAX 8dig display meows+=String(dasss); for (int i = 0; i < 8; i++){display.sendChar (i, meows[i]);}}