//driver for 2 piezos one connevter in highvoltage inverter one connected parralel to ferrit coil >GPIO>220R>DB237>220R>BD140>IRF1404 Gate 220R groundet // 5 taster switching 3v3 to GPIO 220R // 128x64ppixel Oled display //power 5V/2A stepup with 2x18650 6600yF parralel on 5V need high pulscurrent für coils on mosfets.. also AMS1117 5V>3V3 800mA regulator used // 5V stereo NF > 2 Optokoppler (reversed connected to get positive and negativ wave >3v3 optokoppler GPIO optocoppler ground to have value 2048 as zero point have solderer 10nF capacitors to optokopleroutput to reduce murmur #include #include #include #include //open this file to see possible functions // /\/\replace path to zip unzip directory (also in other ccp and h files in folder) //connect display to SCL: PB6 -- SDA: PB7 -- VCC: 5V (3.3V also works) -- GND: G #define OLED_RESET 4 Adafruit_SSD1306 display(OLED_RESET); const unsigned char PROGMEM cat [] = // width 66px height 46 { 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, // ## 0x00, 0x00, 0x0F, 0x0E, 0x18, 0x60, 0x00, 0x00, 0x00, // #### ### ## ## 0x00, 0x00, 0x04, 0x94, 0xF9, 0xE0, 0x00, 0x00, 0x00, // # # # # ##### #### 0x00, 0x00, 0x02, 0x67, 0xB7, 0x40, 0x00, 0x00, 0x00, // # ## #### ## ### # 0x00, 0x3F, 0xFC, 0x22, 0x26, 0x40, 0x00, 0x00, 0x00, // ############ # # # ## # 0x01, 0xE0, 0x04, 0x62, 0x2C, 0x60, 0x00, 0x00, 0x00, // #### # ## # # ## ## 0x07, 0x00, 0x00, 0x02, 0x38, 0x3F, 0xF8, 0x00, 0x00, // ### # ### ########### 0x3C, 0x00, 0x00, 0x02, 0x10, 0x00, 0x0F, 0x80, 0x00, // #### # # ##### 0x60, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, // ## ##### #### 0xDF, 0xE0, 0x7F, 0xE0, 0x01, 0xFE, 0x00, 0x1C, 0x00, // ## ######## ########## ######## ### 0xF0, 0x30, 0xFF, 0xF0, 0x07, 0xFF, 0x00, 0x07, 0x00, // #### ## ############ ########### ### 0x80, 0x18, 0xFF, 0xF0, 0x0F, 0xFF, 0x00, 0x01, 0x80, // # ## ############ ############ ## 0xC0, 0x31, 0xFF, 0xF8, 0x1F, 0xFF, 0x83, 0xFC, 0xC0, // ## ## ############## ############## ######## ## 0x41, 0x19, 0xFF, 0xF8, 0x1F, 0xFF, 0x82, 0x07, 0xC0, // # # ## ############## ############## # ##### 0x61, 0xF1, 0xFF, 0xF8, 0x1F, 0xFF, 0xCE, 0x00, 0x40, // ## ##### ############## ############### ### # 0x20, 0x81, 0xFF, 0xFC, 0x1F, 0xFF, 0xC7, 0xC0, 0x40, // # # ############### ############### ##### # 0x30, 0x71, 0xFF, 0xFC, 0x3F, 0xFF, 0xC0, 0x40, 0xC0, // ## ### ############### ################ # ## 0x10, 0x39, 0x3F, 0xE4, 0x3F, 0xFF, 0xC1, 0x80, 0x80, // # ### # ######### # ################ ## # 0x18, 0x41, 0x00, 0x04, 0x3F, 0xFE, 0x66, 0x00, 0x80, // ## # # # ############# ## ## # 0x0E, 0x01, 0xFF, 0xE4, 0x3F, 0xF0, 0x23, 0x01, 0x80, // ### ############ # ########## # ## ## 0x03, 0x01, 0xC0, 0x3C, 0x20, 0x00, 0x20, 0x03, 0x00, // ## ### #### # # ## 0x01, 0x81, 0x00, 0x08, 0x3F, 0x00, 0x20, 0x02, 0x00, // ## # # ###### # # 0x00, 0x80, 0x00, 0x00, 0x31, 0xFE, 0x60, 0x06, 0x00, // # ## ######## ## ## 0x00, 0xC0, 0x00, 0x00, 0x00, 0x03, 0xC0, 0x0C, 0x00, // ## #### ## 0x00, 0x70, 0x0F, 0xE0, 0x00, 0x00, 0xC0, 0x18, 0x00, // ### ####### ## ## 0x00, 0x1C, 0x38, 0x11, 0xE7, 0xF0, 0x00, 0x30, 0x00, // ### ### # #### ####### ## 0x00, 0x04, 0x60, 0xF1, 0xC3, 0x9C, 0x00, 0x60, 0x00, // # ## #### ### ### ### ## 0x00, 0x0C, 0xC1, 0x80, 0x80, 0xC6, 0x40, 0xC0, 0x00, // ## ## ## # ## ## # ## 0x00, 0x10, 0x83, 0x00, 0x00, 0x60, 0x67, 0x80, 0x00, // # # ## ## ## #### 0x00, 0xE0, 0x06, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, // ### ## #### 0x01, 0x80, 0x04, 0x00, 0x80, 0x80, 0x30, 0x00, 0x00, // ## # # # ## 0x00, 0xFF, 0x80, 0x20, 0x81, 0xF0, 0x0E, 0x00, 0x00, // ######### # # ##### ### 0x00, 0x18, 0x60, 0x11, 0xC6, 0x18, 0x03, 0xC0, 0x00, // ## ## # ### ## ## #### 0x00, 0x60, 0x00, 0x1F, 0x7C, 0x0C, 0x3C, 0x60, 0x00, // ## ##### ##### ## #### ## 0x00, 0x7F, 0x80, 0x14, 0x28, 0x04, 0x07, 0xC0, 0x00, // ######## # # # # # ##### 0x00, 0x43, 0xF0, 0x18, 0x1E, 0x34, 0x01, 0x00, 0x00, // # ###### ## #### ## # # 0x00, 0x02, 0x1C, 0x00, 0x02, 0x1C, 0x3D, 0x00, 0x00, // # ### # ### #### # 0x00, 0x06, 0x00, 0x00, 0x03, 0x10, 0x67, 0x80, 0x00, // ## ## # ## #### 0x00, 0x01, 0xC0, 0x00, 0x01, 0xB0, 0x34, 0x00, 0x00, // ### ## ## ## # 0x00, 0x00, 0x78, 0x00, 0x00, 0xE7, 0xF8, 0x00, 0x00, // #### ### ######## 0x00, 0x00, 0x0E, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, // ### ### 0x00, 0x00, 0x03, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, // ## # 0x00, 0x00, 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, // # # 0x00, 0x00, 0x01, 0x80, 0x00, 0x60, 0x00, 0x00, 0x00, // ## ## 0x00, 0x00, 0x00, 0x80, 0x00, 0x40, 0x00, 0x00, 0x00, // # # 0x00, 0x00, 0x00, 0x80, 0x00, 0x40, 0x00, 0x00, 0x00, // # # }; //use dotfactory to convert picture to array // GPIOusing #define audio PA0 #define meld PC13 //red user led on board #define blau PC15 //taster #define T1 PB12 //switching 470R groundet 3V3 to GPIO #define T2 PB13 #define T3 PB14 #define T4 PB15 #define T5 PA8 #define T6 PA12 //transistormosfetpins #define mos1 PA9 #define mos2 PA10 #define mos3 PB11 //zeilentrafo #define scopedot PA3 //punkt an gird? #define stepperU PA1 #define stepperD PA2 #define stepperR PA4 #define stepperL PA5 void setup() { delay(200); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64) display.clearDisplay(); display.display(); pinMode(T1, INPUT); pinMode(T2, INPUT); pinMode(T3, INPUT); pinMode(T4, INPUT); pinMode(T5, INPUT); pinMode(T6, INPUT); pinMode(meld, OUTPUT); pinMode(blau, OUTPUT); pinMode(mos1, OUTPUT); pinMode(mos2, OUTPUT); pinMode(mos3, OUTPUT); pinMode(stepperR, OUTPUT); pinMode(stepperL, OUTPUT); pinMode(stepperU, OUTPUT); pinMode(stepperD, OUTPUT); pinMode(scopedot, OUTPUT); digitalWrite(meld,LOW);//usedled is inverted delay(200); } uint8_t onpress[13]; uint16_t welch,setzen,speedy; uint16_t nochwas=42;//audioreadintervall microsecond uint16_t sensivity=32;//zeroline uint16_t etwas=19;// peak level size on waveline uint8_t sound[128]; uint16_t soundm[128]; uint8_t tubebuffer[129][64]; String michauch=""; boolean ONOFF=false; uint16_t araypos,piezopos; void loop() { //istserial(); //machCATZ(); digitalWrite(meld,HIGH); zeitreise(); } void drueckmich(void){ if (onpress[10] >=2) { if (digitalRead(T1) == HIGH && onpress[0] ==0 ) { onpress[0]=1; setzden(setzen,true); } if (onpress[0] == 1) { onpress[1]++; } if (onpress[1] >= speedy) { onpress[1] =0; onpress[0]=0; } if (digitalRead(T2) == HIGH && onpress[2] ==0 ) { onpress[2] =1; setzden(setzen,false); } if (onpress[2] == 1) { onpress[3]++; } if (onpress[3] >= speedy) { onpress[3] =0; onpress[2]=0; } if (digitalRead(T3) == HIGH && onpress[4] ==0 ) { onpress[4] =1; setzen++; if (setzen >3) {setzen=0;} } 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; ONOFF=true;} if (onpress[6] == 1) { onpress[7]++; } if (onpress[7] >= 20) { 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] >= 20) { onpress[9] =0; onpress[8]=0; } onpress[10]=0; if((digitalRead(T1) == HIGH)||(digitalRead(T2) == HIGH)||(digitalRead(T3) == HIGH)||(digitalRead(T4) == HIGH)||(digitalRead(T5) == HIGH)){malscreen();} }} void setzden(int welch,boolean updown){ if(welch==0 && updown==true && sensivity <4000){sensivity++;speedy=10;} if(welch==0 && updown==false && sensivity >=1){sensivity--;speedy=10;} if(welch==1 && updown==true && etwas <(500)){etwas++;speedy=2 ;} if(welch==1 && updown==false && etwas >=1){etwas--;speedy=5;} if(welch==3 && updown==false && nochwas <(4000)){nochwas++;} if(welch==3 && updown==true && nochwas >1){nochwas--;} } void malscreen(){ display.clearDisplay();//84 48# display.drawRect(setzen*32,0,27,11,WHITE); zahlso(2,2,soundm[5],1); zahlso(34,2,etwas,1); zahlso(66,2,analogRead(audio),1); zahlso(98,2,nochwas,1); for(uint8_t zomg=0;zomg<128;zomg++){display.drawPixel(zomg,64-sound[zomg],WHITE);} display.display(); if(ONOFF == true){digitalWrite(blau,HIGH);}else{digitalWrite(blau,LOW);} } void textso(int xhier,int yhier,String was,int gros){display.setCursor(xhier,yhier);display.setTextSize(gros); display.print(was);} void zahlso(int xda,int yda,int mich,int grosz){String michauch=""; display.setTextSize(grosz); display.setCursor(xda,yda); display.setTextColor(WHITE); if (mich <9) {michauch+="0";} if (mich <99) {michauch+="0";} if (mich <999) {michauch+="0";} michauch+=mich; display.println(michauch);} long maintime=millis();long beaty=micros(); long timez=micros(); long flash=micros(); uint16_t bildslow=0; void zeitreise(void){ while ((millis()- maintime) >= 2){onpress[10]++; drueckmich();maintime = millis(); bildslow++;if(bildslow >1000){maltube();bildslow=0;}} while ((micros()- beaty) >= 2) {zeilentrafo(20,40);//40,40 beaty=micros();} araypos=1; if(ONOFF==true){ while((araypos > 0) ||(digitalRead(T6)==HIGH)){ while ((micros()- timez) >= 42) { piezopos++;if(piezopos>128){piezopos=0;} // if(digitalRead(T6)==HIGH){ chirp(soundm[piezopos]-1900,2);} timez = micros();} while ((micros()-flash) >= nochwas) { //caused 24000Hz = 41.6666666.. microseconds araypos++;if(araypos>128){araypos=0;} wuselsound(); flash = micros();}} } } void wuselsound(void){ soundm[araypos]=(analogRead(audio)); sound[araypos]=sensivity+((soundm[araypos]-2048)/etwas); } uint16_t dutycach=200;uint16_t hole=0; void chirp(int wiehoch,int wer) { nomos(); for (uint8_t wusch=0; wusch <=(dutycach+hole); wusch++) { if (wusch == 0) {nomos();} if (wusch <= (dutycach-1) && wusch >=1) { if ((wusch == (dutycach-wiehoch))&& wer==1) { digitalWrite(mos1, HIGH);} if ((wusch == (dutycach-wiehoch))&& wer==2) { digitalWrite(mos2, HIGH);}} if (wusch >=(dutycach+hole)) { nomos();} }} void maltube(void){ flushbuffer(); wavetobuffer(); bild(); } void wavetobuffer(void){ for (uint8_t positor=0; positor<(128); positor++) { tubebuffer[positor][64-sound[positor]]=1; }} void flushbuffer(void){ for (uint8_t pozitor=0; pozitor<(128); pozitor++) { for (uint8_t prositor=0; prositor<(64); prositor++) { tubebuffer[pozitor][prositor]=0; tubebuffer[1][prositor]=1;tubebuffer[pozitor][1]=1; } } } void bild(void) { ablenk(2);delayMicroseconds(4); for (uint8_t zeile=0; zeile<(64); zeile++) { strich(1); delayMicroseconds(4); for (uint8_t doty=0; doty<(128); doty++) { for (uint16_t slower=0; slower<=(1); slower++) { //digitalWrite(scopedot,HIGH); if(tubebuffer[doty][zeile]==0){digitalWrite(scopedot,LOW);} if(tubebuffer[doty][zeile]==1){digitalWrite(scopedot,HIGH);} } } digitalWrite(scopedot,LOW); strich(2); delayMicroseconds(20); }ablenk(1);delayMicroseconds(5); } void ablenk(uint8_t raufrunter){ if (raufrunter==0) {digitalWrite(stepperU,LOW);digitalWrite(stepperD,LOW);} if (raufrunter==1) {digitalWrite(stepperD,LOW);digitalWrite(stepperU,HIGH);} if (raufrunter==2) {digitalWrite(stepperU,LOW);digitalWrite(stepperD,HIGH);} } void strich(uint8_t rechtslinks){ if (rechtslinks==0){digitalWrite(stepperR,LOW);digitalWrite(stepperL,LOW);} if (rechtslinks==1){digitalWrite(stepperL,LOW);digitalWrite(stepperR,HIGH);} if (rechtslinks==2){digitalWrite(stepperR,LOW);digitalWrite(stepperL,HIGH);delayMicroseconds(150);} } void zeilentrafo(int duty,int often) { digitalWrite(mos3, LOW); for (uint16_t sooft=0; sooft<=(often); sooft++) { for (uint16_t wuschz=0; wuschz <=(dutycach+hole); wuschz++) { if (wuschz == 0) {digitalWrite(mos3, LOW);} if (wuschz <= (dutycach-1) && wuschz >=1) { if (wuschz == (dutycach-duty)) { digitalWrite(mos3, HIGH);}} if (wuschz >=(dutycach+hole)) { digitalWrite(mos3, LOW);} }}} int8_t posr,posrm,posrr,posrrm,randy,randy2; void machCATZ() { if (posr >randy2) {posrm=1;randy2=random(20,5);} if (posrm ==1) {posr--;} if (posr <1) {posrm =0;} if (posrm ==0) {posr++;} if (posrr >randy) {posrrm=1; randy=random(55,10);} if (posrrm ==1) {posrr--; } if (posrr <1) {posrrm =0;} if (posrrm ==0) {posrr++;} display.drawBitmap(55-posrr, 20-posr,cat,66, 46, WHITE); display.display(); } void nomos(void) {digitalWrite(mos1,LOW); digitalWrite(mos2,LOW); digitalWrite(mos3,LOW); } /* * MEOW! For using the SSD1306 I2C onb STM32F1203C8T6 with adafruit * by marderchen =^.^= its free use it or parts if there is something usefull * do what you want! * ___ * _.-| | / |\__/,| (`\ { | | -- |^ ^ |__ _) ) "-.|___| \ _.( Y ) ` / .--'-`-. _((_ `^--' /__< \ ....-+|______|__.-||__)`-' (((/ (((/ CATS are awesome! */