//test for driving Lightener inverter think get better signal with stm32>F103C8T6 (replacing NE555 citcuit) //schematic GPIO->220R->D882 (NPN3ASMD)->220R ->BD140 (PNP2APCB)->IRF1404 (N-channel mosfet) gate groundet with 2x 470Rparralel //not finished now but running just easyer using a TM1638 DIG/taster module than debug over seriall //have fun use if usefull.. by marderchen #include #include #define NO_MODULES 1 // datathinks PB12 - clockthinks PB13- Strobethinks PB14 TM1638 module(PB12, PB13, PB14);// 3wires to STM + gnd and 5V TM1638* modules[NO_MODULES] = {&module,}; byte modes[NO_MODULES]; #define NO_MODULES 1 #define rot PC13 #define MOSI PA0 #define t1 PB5 #define t2 PB6 #define t3 PB7 #define t4 PB8 uint8_t onpress[15],zeit1; uint16_t temps[5],offtimecount; uint16_t errortemp=1000; uint32_t offtime=50; uint16_t laag=50; 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(MOSI, OUTPUT); pinMode(t1, INPUT); pinMode(t2, INPUT); pinMode(t3 ,INPUT); pinMode(t4 ,INPUT); digitalWrite(MOSI,LOW); for (int i = 0; i < NO_MODULES; i++) { module.setupDisplay(true, 8); modes[i] = 0; } delay(300); } void loop() { istinput(); zeitreise(); //if (onk==true) {digitalWrite(grun,HIGH);}else {digitalWrite(grun,LOW);} } String cach=""; void update(TM1638* module, byte* mode) { byte buttons = module->getButtons(); if (buttons ==1) {offtime++;} if (buttons ==2&&offtime>1) {offtime--;} if (buttons ==4) {laag++;} if (buttons ==8&&laag>1) {laag--;} if (buttons ==16) {} if (buttons ==32) {} if (buttons ==64) {} if (buttons ==128) {} cach =""; if(offtime<=9){cach+="0";} if(offtime<=99){cach+="0";} if(offtime<=999){cach+="0";} cach+=offtime; if(laag<=9){cach+="0";} if(laag<=99){cach+="0";} if(laag<=999){cach+="0";} cach+=laag; module->setDisplayToString(cach); } 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(t1) == 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; } zeit1=0;}} void zeitreise(void){ while ((millis()- maintime) >= 5){zeit1++; maintime = millis();} while ((micros()- maintime3) >= 60) { maintime3 = micros();} while ((millis()- maintime2) >= 60) { for (int i = 0; i < NO_MODULES; i++) {update(modules[i], &modes[i]);} maintime2 = millis();} while ((millis()- timez) >= 998) {timez = millis();} while ((micros()-mosipulsi) >= 2) {while(digitalRead(t3) == HIGH) {pulspower();} digitalWrite(MOSI,LOW); mosipulsi = micros(); }} void pulspower() { for (uint32_t often=0; often <(200); often++) { for (uint32_t fcount=0; fcount <(offtime*2); fcount++) { if (fcount==0) {digitalWrite(MOSI, HIGH); digitalWrite(rot, LOW);} if (fcount==1) {digitalWrite(MOSI, HIGH); } if (fcount>=(laag+1)){digitalWrite(MOSI, LOW); digitalWrite(rot, HIGH);} }}}