
possibly simultaneously
Dependencies: TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG
Diff: main.cpp
- Revision:
- 1:19138bfe23c9
- Parent:
- 0:d2b5a1e8fc0c
- Child:
- 2:58378cb7e76f
--- a/main.cpp Wed May 01 19:46:14 2019 +0000 +++ b/main.cpp Fri May 03 13:27:39 2019 +0000 @@ -1,19 +1,26 @@ #include "mbed.h" #include "TS_DISCO_F746NG.h" #include "LCD_DISCO_F746NG.h" +#include"sn44.h" +#include"cl44.h" +#include"clhh44.h" +#include"ophh44.h" +#include"kick44.h" +#define sample_freq 16000.0 DigitalOut led(LED1); LCD_DISCO_F746NG lcd; TS_DISCO_F746NG ts; AnalogIn tempoknob(A1); AnalogIn volumeknob(A0); - +PwmOut speaker(D1); Serial pc(USBTX, USBRX); -Ticker re,er,rr,ee; //timer ไว้ attach ตอนplay audio กับไว้รับปุ่ม +Ticker re,er,rr,ee,sn44tick,cl44tick,clhh44tick,ophh44tick,kick44tick;//timer ไว้ attach ตอนplay audio กับไว้รับปุ่ม int checkplay=1,beat[5][8],page=1; -char currentpage[50],tempochar[50],volumechar[50],strvolume[50],strtempo[50]; //สร้างไว้ให้เขียนอักษรได้เฉยๆ +char currentpage[50],volumechar[50],strvolume[50],strtempo[50],tempostr[50]; //สร้างไว้ให้เขียนอักษรได้เฉยๆ float volume,tempo; +int i=0; void test(void); //function for touchscreen void play(void);// function for play void screen(void);//function for display @@ -26,8 +33,117 @@ re.attach(&play, 0.1);//เล่นตามsamplerate er.attach(&test, 0.25);//กดช้ากดเร็วแล้วแต่ rr.attach(&knob,0.5);//readknob ทุก0.5 + + } + +//SAMPLE && SAMPLE PLAY FUNCTION + +void sn44_sample () +{ + + speaker = sn44_data[i]/16777215.0;//scale to 0.0 to 1.0 for PWM + i++; + if (i>= num_sn44) { + i = 0; + sn44tick.detach(); + led = 0; + } +} +void cl44_sample () +{ + + speaker = cl44_data[i]/16777215.0;//scale to 0.0 to 1.0 for PWM + i++; + if (i>= num_cl44) { + i = 0; + cl44tick.detach(); + led = 0; + } +} +void clhh44_sample () +{ + + speaker = clhh44_data[i]/16777215.0;//scale to 0.0 to 1.0 for PWM + i++; + if (i>= num_clhh44) { + i = 0; + clhh44tick.detach(); + led = 0; + } +} +void ophh44_sample () +{ + + speaker = ophh44_data[i]/16777215.0;//scale to 0.0 to 1.0 for PWM + i++; + if (i>= num_ophh44) { + i = 0; + ophh44tick.detach(); + led = 0; + } +} +void kick44_sample () +{ + + speaker = kick44_data[i]/16777215.0;//scale to 0.0 to 1.0 for PWM + i++; + if (i>= num_kick44) { + i = 0; + kick44tick.detach(); + led = 0; + } +} + +void playsnare() +{ + speaker.period(1.0/330750.0); //PWM freq >10X audio sample rate + + + sn44tick.attach(&sn44_sample, 1.0 / 33075); + + wait(0.5); + +} +void playkick() +{ + speaker.period(1.0/441000.0); //PWM freq >10X audio sample rate + + + kick44tick.attach(&kick44_sample, 1.0 / 33075); + + wait(0.2); + +} +void playclap() +{ + speaker.period(1.0/220500.0); //PWM freq >10X audio sample rate + + + cl44tick.attach(&cl44_sample, 1.0 /22050); + + wait(0.5); + +} +void playclhh() +{ + speaker.period(1.0/330750.0); //PWM freq >10X audio sample rate + + clhh44tick.attach(&clhh44_sample, 1.0 / 33075); + + wait(0.5); + +} +void playophh() +{ + speaker.period(1.0/330750.0); //PWM freq >10X audio sample rate + ophh44tick.attach(&ophh44_sample, 1.0 / 33075); + + wait(0.2); + +} +//////////////////////////////////////////////////////////////// void play() { if(checkplay==1)//led blink when button play is on @@ -40,10 +156,11 @@ } } + void test() { TS_StateTypeDef TS_State; - uint8_t status;//ไม่ได้ใช้สร้างไว้ก่อน + /*uint8_t status;//ไม่ได้ใช้สร้างไว้ก่อน*/ ts.GetState(&TS_State); if((TS_State.touchDetected))//รับtouchอะไรก็ตาม จะเข้าfunctionนี้ { @@ -81,14 +198,19 @@ } if(TS_State.touchX[0]<122&&TS_State.touchX[0]>98&&TS_State.touchY[0]<248&&TS_State.touchY[0]>198)//beat1 { + if(beat[page-1][0]==0) { beat[page-1][0]=1; - } + + } else if(beat[page-1][0]==1) { beat[page-1][0]=0; } + + + } if(TS_State.touchX[0]<166&&TS_State.touchX[0]>142&&TS_State.touchY[0]<248&&TS_State.touchY[0]>198)//beat2 { @@ -194,9 +316,9 @@ volume=(volumeknob.read()*100);//0to100 tempo=(tempoknob.read()*100);//problematic******************************************** - sprintf(tempochar,"%1.1f",tempo); + sprintf(tempostr,"%1.1f",tempo); sprintf(volumechar,"%1.1f",volume); - pc.printf("tempo = %s \n\r",tempochar); //print ในuart ถูก + pc.printf("tempo = %s \n\r",tempostr); //print ในuart ถูก pc.printf("volume = %s\n\r",volumechar); } @@ -224,40 +346,42 @@ sprintf(strtempo,"%s","Tempo "); lcd.SetTextColor(LCD_COLOR_BLACK); lcd.DisplayStringAt(24,LINE(1),(uint8_t*)strtempo,RIGHT_MODE); - sprintf(tempochar,"%s",tempochar); ////////////////////////////////////////////display tempo on lcd ไม่ถูก + sprintf(tempostr,"%1.1f",tempo); ////////////////////////////////////////////display tempo on lcd ไม่ถูก lcd.SetTextColor(LCD_COLOR_BLACK); - lcd.DisplayStringAt(24,LINE(2),(uint8_t*)tempochar,RIGHT_MODE); + lcd.DisplayStringAt(24,LINE(2),(uint8_t*)tempostr,RIGHT_MODE); if(page==1) //พวกนี้คือแสดงหน้าว่าอยู่หน้าอะไร { - sprintf(currentpage,"%s","Current page is Drum1"); + sprintf(currentpage,"%s","Current page is Kick "); lcd.SetTextColor(LCD_COLOR_BLACK); lcd.DisplayStringAt(24,LINE(3),(uint8_t*)currentpage,LEFT_MODE); + } else if(page==2) { - sprintf(currentpage,"%s","Current page is Drum2"); + sprintf(currentpage,"%s","Current page is Snare "); lcd.SetTextColor(LCD_COLOR_BLACK); lcd.DisplayStringAt(24,LINE(3),(uint8_t*)currentpage,LEFT_MODE); + } else if(page==3) { - sprintf(currentpage,"%s","Current page is Drum3"); + sprintf(currentpage,"%s","Current page is Clap "); lcd.SetTextColor(LCD_COLOR_BLACK); lcd.DisplayStringAt(24,LINE(3),(uint8_t*)currentpage,LEFT_MODE); } else if(page==4) { - sprintf(currentpage,"%s","Current page is Drum4"); + sprintf(currentpage,"%s","Current page is Close HiHat "); lcd.SetTextColor(LCD_COLOR_BLACK); lcd.DisplayStringAt(24,LINE(3),(uint8_t*)currentpage,LEFT_MODE); } else if(page==5) { - sprintf(currentpage,"%s","Current page is Drum5"); + sprintf(currentpage,"%s","Current page is Open HiHat "); lcd.SetTextColor(LCD_COLOR_BLACK); lcd.DisplayStringAt(24,LINE(3),(uint8_t*)currentpage,LEFT_MODE); }