//tesla coil driver with selvduild 2digs + 7ledsbar leddisplay #define dig1 PB5 //dig/sekt vertauschjt #define dig2 PB6 #define dig3 PB7 #define dig4 PB8 #define dig5 PB9 #define dig6 PB15 #define dig7 PA8 #define seg1 PA9 #define seg2 PA10 #define seg3 PC14 #define trans1 PB11 //mos #define trans2 PB10 //PNP #define trans3 PB1 //NPN #define trans4 PB0 //NPN #define t1 PB12 #define t2 PB13 #define t3 PB14 #define t4 PA12 #define t5 PA15 #define user PC13 int16_t digitise[4][10]; //last: brighteness uint16_t bar[9]; int8_t onpress[14]; uint16_t fadefine=200; int ani =199; int aus=0; uint32_t teslapower=10; uint32_t teslarepeat=10; uint32_t teslabreak=2; uint16_t dotys; int8_t zeitregen,blinkt; uint8_t setzen=1; long maintime=millis(); long maintime2=micros(); long maintime3=millis(); String showme=""; void setup() { pinMode(dig1, OUTPUT); pinMode(dig2, OUTPUT); pinMode(dig3, OUTPUT); pinMode(dig4, OUTPUT); pinMode(dig5, OUTPUT); pinMode(dig6, OUTPUT); pinMode(dig7, OUTPUT); pinMode(seg1, OUTPUT); pinMode(seg2, OUTPUT); pinMode(seg3, OUTPUT); pinMode(t1, INPUT); pinMode(t2, INPUT); pinMode(t3, INPUT); pinMode(t4, INPUT); pinMode(t5, INPUT); pinMode(trans1, OUTPUT); pinMode(trans2, OUTPUT); pinMode(trans3, OUTPUT); pinMode(trans4, OUTPUT); pinMode(user, OUTPUT); } boolean onoff=false; void loop() { zeitreise(); machlicht(); drueckmich(); } void drueckmich(void){ if (onpress[12] >=3) { if (digitalRead(t1) == HIGH && onpress[0] ==0 ) { onpress[0] =1; setzen++; if (setzen >3) {setzen=1;} } if (onpress[0] == 1) { onpress[1]++; } if (onpress[1] >= 15) { onpress[1] =0; onpress[0]=0; } if (digitalRead(t2) == HIGH && onpress[2] ==0 ) { onpress[2] =1; setzden(setzen,true); } if (onpress[2] == 1) { onpress[3]++; } if (onpress[3] >= 5) { onpress[3] =0; onpress[2]=0; } if (digitalRead(t3) == HIGH && onpress[4] ==0 ) { onpress[4] =1; setzden(setzen,false);} if (onpress[4] == 1) { onpress[5]++; } if (onpress[5] >= 5) { onpress[5] =0; onpress[4]=0; } if (digitalRead(t4) == HIGH && onpress[6] ==0 ) { onpress[6] =1; onoff=true;} if (onpress[6] == 1) { onpress[7]++; } if (onpress[7] >= 5) { onpress[7] =0; onpress[6]=0; } if (digitalRead(t5) == HIGH && onpress[8] ==0 ) { onpress[8] =1; onoff=false;} if (onpress[8] == 1) { onpress[9]++; } if (onpress[9] >= 5) { onpress[9] =0; onpress[8]=0; } digitalWrite(user,HIGH); if ((digitalRead(t1) ||digitalRead(t2) ||digitalRead(t3) ||digitalRead(t4) ||digitalRead(t5))==HIGH){digitalWrite(user,LOW);} onpress[12]=0; }}//tagrum void setzden(int chosenone,boolean updown) { if(updown==true){ if (chosenone==1 && teslapower = 1) {teslapower-=1;} if (chosenone==2 && teslarepeat >= 1) {teslarepeat-=1;} if (chosenone==3 && teslabreak >= 12) {teslabreak-=1;} } if (chosenone==1){zeigmal(teslapower);} if (chosenone==2){zeigmal(teslarepeat);} if (chosenone==3){zeigmal(teslabreak);} } void zeigmal(int16_t wasden){ showme=""; if (wasden <=9){ showme+="0";} showme +=wasden; refresh(); } void refresh() { zeigzeugs(0,showme[0]); zeigzeugs(1,showme[1]); } uint32_t fadecach=0; void zeitreise(void){ while ((millis()- maintime) >= 10) { onpress[12]++; if (setzen !=0) {refresh();} downfade(); maintime = millis(); } while ((millis()- maintime2) >= 50) { maintime2 = millis(); if(setzen==1){bar[0]=fadefine;} if(setzen==2){bar[1]=fadefine;} if(setzen==3){bar[2]=fadefine;} if(onoff==true){bar[6]=fadefine;} refresh(); } while ((micros()- maintime3) >= 2000) { fadecach=fadefine*teslabreak; if(onoff == true){ for (uint32_t fcount1=0; fcount1 <(teslarepeat*10); fcount1++) { for (uint32_t fcount2=0; fcount2 <(fadecach+2); fcount2++) { if (fcount2 == (fadecach-teslapower)) {digitalWrite(trans1, HIGH);} if (fcount2 > (fadecach-1)) {digitalWrite(trans1,LOW);}}} }maintime3 = micros(); }} uint8_t steptz=2; void downfade(void) { for (int16_t digs=0; digs <=8; digs++) { if(bar[digs]>=(steptz*4)) { bar[digs]-=steptz*4;} for (int16_t ad=0; ad <=2; ad++) { if(digitise[digs][ad]>steptz) { digitise[digs][ad]-=steptz;} }} } /*thingy showing 0 in dig "PLAN" dots between are 8 in dig 6(if starting with1 and not 0) first dig from left.. * hihi i know there must be a better solution better but better using my one caused its working fine :3 * * ---1-- * | | * 3 2 []8 * | | * ---4--- * | | * 5 6 []8 * | | * ---7--- */ void zeigzeugs(int welchezahl,char wasden) { if (wasden == 'S') {wasden='5';} if (wasden == 'e') {wasden='9';} if (wasden == 'R') {wasden='A';} if (wasden == '0') {digitise[welchezahl][1]=ani; digitise[welchezahl][2]=ani; digitise[welchezahl][3]=ani; digitise[welchezahl][4]=aus; digitise[welchezahl][5]=ani; digitise[welchezahl][6]=ani; digitise[welchezahl][7]=ani;} if (wasden == '1') {digitise[welchezahl][1]=aus; digitise[welchezahl][2]=ani; digitise[welchezahl][3]=aus; digitise[welchezahl][4]=aus; digitise[welchezahl][5]=aus; digitise[welchezahl][6]=ani; digitise[welchezahl][7]=aus;} if (wasden == '2') {digitise[welchezahl][1]=ani; digitise[welchezahl][2]=ani; digitise[welchezahl][3]=aus; digitise[welchezahl][4]=ani; digitise[welchezahl][5]=ani; digitise[welchezahl][6]=aus; digitise[welchezahl][7]=ani;} if (wasden == '3') {digitise[welchezahl][1]=ani; digitise[welchezahl][2]=ani; digitise[welchezahl][3]=aus; digitise[welchezahl][4]=ani; digitise[welchezahl][5]=aus; digitise[welchezahl][6]=ani; digitise[welchezahl][7]=ani;} if (wasden == '4') {digitise[welchezahl][1]=aus; digitise[welchezahl][2]=ani; digitise[welchezahl][3]=ani; digitise[welchezahl][4]=ani; digitise[welchezahl][5]=aus; digitise[welchezahl][6]=ani; digitise[welchezahl][7]=aus;} if (wasden == '5') {digitise[welchezahl][1]=ani; digitise[welchezahl][2]=aus; digitise[welchezahl][3]=ani; digitise[welchezahl][4]=ani; digitise[welchezahl][5]=aus; digitise[welchezahl][6]=ani; digitise[welchezahl][7]=ani;} if (wasden == '6') {digitise[welchezahl][1]=ani; digitise[welchezahl][2]=aus; digitise[welchezahl][3]=ani; digitise[welchezahl][4]=ani; digitise[welchezahl][5]=ani; digitise[welchezahl][6]=ani; digitise[welchezahl][7]=ani;} if (wasden == '7') {digitise[welchezahl][1]=ani; digitise[welchezahl][2]=ani; digitise[welchezahl][3]=aus; digitise[welchezahl][4]=aus; digitise[welchezahl][5]=aus; digitise[welchezahl][6]=ani; digitise[welchezahl][7]=aus;} if (wasden == '8') {digitise[welchezahl][1]=ani; digitise[welchezahl][2]=ani; digitise[welchezahl][3]=ani; digitise[welchezahl][4]=ani; digitise[welchezahl][5]=ani; digitise[welchezahl][6]=ani; digitise[welchezahl][7]=ani;} if (wasden == '9') {digitise[welchezahl][1]=ani; digitise[welchezahl][2]=ani; digitise[welchezahl][3]=ani; digitise[welchezahl][4]=ani; digitise[welchezahl][5]=aus; digitise[welchezahl][6]=ani; digitise[welchezahl][7]=ani;} if (wasden == ' ') {digitise[welchezahl][1]=aus; digitise[welchezahl][2]=aus; digitise[welchezahl][3]=aus; digitise[welchezahl][4]=aus; digitise[welchezahl][5]=aus; digitise[welchezahl][6]=aus; digitise[welchezahl][7]=aus;} if (wasden == 'A') {digitise[welchezahl][1]=ani; digitise[welchezahl][2]=ani; digitise[welchezahl][3]=ani; digitise[welchezahl][4]=ani; digitise[welchezahl][5]=ani; digitise[welchezahl][6]=ani; digitise[welchezahl][7]=aus;} if (wasden == 'L') {digitise[welchezahl][1]=aus; digitise[welchezahl][2]=aus; digitise[welchezahl][3]=ani; digitise[welchezahl][4]=aus; digitise[welchezahl][5]=ani; digitise[welchezahl][6]=aus; digitise[welchezahl][7]=ani;} if (wasden == 't') {digitise[welchezahl][1]=ani; digitise[welchezahl][2]=ani; digitise[welchezahl][3]=ani; digitise[welchezahl][4]=aus; digitise[welchezahl][5]=ani; digitise[welchezahl][6]=aus; digitise[welchezahl][7]=ani;} if (wasden == 'i') {digitise[welchezahl][1]=aus; digitise[welchezahl][2]=aus; digitise[welchezahl][3]=aus; digitise[welchezahl][4]=aus; digitise[welchezahl][5]=aus; digitise[welchezahl][6]=ani; digitise[welchezahl][7]=aus;} if (wasden == 'm') {digitise[welchezahl][1]=aus; digitise[welchezahl][2]=aus; digitise[welchezahl][3]=aus; digitise[welchezahl][4]=ani; digitise[welchezahl][5]=ani; digitise[welchezahl][6]=ani; digitise[welchezahl][7]=aus;} if (wasden == 'H') {digitise[welchezahl][1]=aus; digitise[welchezahl][2]=ani; digitise[welchezahl][3]=ani; digitise[welchezahl][4]=ani; digitise[welchezahl][5]=ani; digitise[welchezahl][6]=ani; digitise[welchezahl][7]=aus;} if (wasden == 'o') {digitise[welchezahl][1]=aus; digitise[welchezahl][2]=aus; digitise[welchezahl][3]=aus; digitise[welchezahl][4]=ani; digitise[welchezahl][5]=ani; digitise[welchezahl][6]=ani; digitise[welchezahl][7]=ani;} if (wasden == 'U') {digitise[welchezahl][1]=aus; digitise[welchezahl][2]=ani; digitise[welchezahl][3]=ani; digitise[welchezahl][4]=aus; digitise[welchezahl][5]=ani; digitise[welchezahl][6]=ani; digitise[welchezahl][7]=ani;} if (wasden == 'E') {digitise[welchezahl][1]=ani; digitise[welchezahl][2]=aus; digitise[welchezahl][3]=ani; digitise[welchezahl][4]=ani; digitise[welchezahl][5]=ani; digitise[welchezahl][6]=aus; digitise[welchezahl][7]=ani;} if (wasden == 'C') {digitise[welchezahl][1]=ani; digitise[welchezahl][2]=aus; digitise[welchezahl][3]=ani; digitise[welchezahl][4]=aus; digitise[welchezahl][5]=ani; digitise[welchezahl][6]=aus; digitise[welchezahl][7]=ani;} //see how simple it is brain :3 } long startriger=micros(); void machlicht(void) { digitalWrite(trans1,LOW); while ((micros()-startriger) >= 10) { for (int16_t sekt=1; sekt <=3; sekt++) { noseg(); if(sekt ==1) {digitalWrite(seg1, LOW );} if(sekt ==2) {digitalWrite(seg2, LOW );} if(sekt ==3) {digitalWrite(seg3, LOW );} for (int16_t fcount1=0; fcount1 <(fadefine+2); fcount1++) { if (fcount1 == 0) {nodig();} if (fcount1 < fadefine && fcount1>=1 && sekt <=2) { if (fcount1 == ((fadefine)-digitise[sekt-1][1])) { digitalWrite(dig1, LOW );} if (fcount1 == ((fadefine)-digitise[sekt-1][2])) { digitalWrite(dig2, LOW );} if (fcount1 == ((fadefine)-digitise[sekt-1][3])) { digitalWrite(dig3, LOW );} if (fcount1 == ((fadefine)-digitise[sekt-1][4])) { digitalWrite(dig4, LOW );} if (fcount1 == ((fadefine)-digitise[sekt-1][5])) { digitalWrite(dig6, LOW );} if (fcount1 == ((fadefine)-digitise[sekt-1][6])) { digitalWrite(dig5, LOW );} if (fcount1 == ((fadefine)-digitise[sekt-1][7])) { digitalWrite(dig7, LOW );} } if (fcount1 < fadefine && fcount1>=1 && sekt ==3) { if (fcount1 == (fadefine-bar[0])) { digitalWrite(dig1, LOW );} if (fcount1 == (fadefine-bar[1])) { digitalWrite(dig2, LOW );} if (fcount1 == (fadefine-bar[2])) { digitalWrite(dig3, LOW );} if (fcount1 == (fadefine-bar[3])) { digitalWrite(dig4, LOW );} if (fcount1 == (fadefine-bar[4])) { digitalWrite(dig5, LOW );} if (fcount1 == (fadefine-bar[5])) { digitalWrite(dig6, LOW );} if (fcount1 == (fadefine-bar[6])) { digitalWrite(dig7, LOW );} } if (fcount1 > (fadefine-1)) {nodig(); noseg();} }} startriger = micros(); } } void nodig(void) { digitalWrite(dig1, HIGH ); digitalWrite(dig2, HIGH ); digitalWrite(dig3, HIGH ); digitalWrite(dig4, HIGH ); digitalWrite(dig5, HIGH ); digitalWrite(dig6,HIGH ); digitalWrite(dig7, HIGH ); } void noseg(void) { digitalWrite(seg1, HIGH ); digitalWrite(seg2, HIGH ); digitalWrite(seg3, HIGH ); } //[MEOW] project by marderchen us3e it or parts if usefull :3