
volumetempofix
Dependencies: TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG
Revision 4:ec0ff5b355e8, committed 2019-05-04
- Comitter:
- chana_jo
- Date:
- Sat May 04 17:41:04 2019 +0000
- Parent:
- 3:3a2c11f459c4
- Commit message:
- endme;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat May 04 09:19:10 2019 +0000 +++ b/main.cpp Sat May 04 17:41:04 2019 +0000 @@ -17,8 +17,8 @@ Serial pc(USBTX, USBRX); Ticker re,er,rr,ee,sn44tick,cl44tick,clhh44tick,ophh44tick,kick44tick,testprint;//timer ไว้ attach ตอนplay audio กับไว้รับปุ่ม -int checkplay=1,beat[5][8],page=1; -int tracking; +int checkplay=0,beat[5][8],page=1; +int tracking=1; char currentpage[50],volumechar[50],strvolume[50],strtempo[50],tempostr[50]; //สร้างไว้ให้เขียนอักษรได้เฉยๆ float volume,tempo; float speed; //tempo converted to sec @@ -29,14 +29,15 @@ void knob(void);// read knob void testbeat1(void); void testbeat2(void); +float tempo2,volume2; int main() { lcd.Clear(LCD_COLOR_BLUE); ee.attach(&screen, 0.03); - re.attach(&play, speed);//เล่นตามtempo + re.attach(&play, 0.5);//เล่นตามtempo er.attach(&test, 0.25);//กดช้ากดเร็วแล้วแต่ - //rr.attach(&knob,0.5);//readknob ทุก0.5 + rr.attach(&knob,0.5);//readknob ทุก0.5 } @@ -103,7 +104,7 @@ { speaker = sn44_data[h]/16777215.0;//scale to 0.0 to 1.0 for PWM h++; - speaker.period(1.0/330750.0); //PWM freq >10X audio sample rate + speaker.period((1.0/330750.0)*volume); //PWM freq >10X audio sample rate if (h>= num_sn44) { h = 0; @@ -116,7 +117,7 @@ { speaker = kick44_data[l]/16777215.0;//scale to 0.0 to 1.0 for PWM l++; - speaker.period(1.0/441000.0); //PWM freq >10X audio sample rate + speaker.period((1.0/441000.0)*volume); //PWM freq >10X audio sample rate if (l>= num_kick44) { l = 0; @@ -128,7 +129,7 @@ { speaker = cl44_data[i]/16777215.0;//scale to 0.0 to 1.0 for PWM i++; - speaker.period(1.0/220500.0); //PWM freq >10X audio sample rate + speaker.period((1.0/220500.0)*volume); //PWM freq >10X audio sample rate if (i>= num_cl44) { i = 0; @@ -141,7 +142,7 @@ { speaker = clhh44_data[j]/16777215.0;//scale to 0.0 to 1.0 for PWM j++; - speaker.period(1.0/330750.0); //PWM freq >10X audio sample rate + speaker.period((1.0/330750.0)*volume); //PWM freq >10X audio sample rate if (j>= num_clhh44) { j = 0; @@ -154,7 +155,7 @@ { speaker = ophh44_data[k]/16777215.0;//scale to 0.0 to 1.0 for PWM k++; - speaker.period(1.0/330750.0); //PWM freq >10X audio sample rate + speaker.period((1.0/330750.0)*volume); //PWM freq >10X audio sample rate if (k>= num_ophh44) { k = 0; @@ -167,13 +168,8 @@ { if(checkplay==1)//led blink when button play is on { - pc.printf("current beat : %d ",tracking); - if(tracking<8) - tracking=tracking+1; - else if(tracking==8) - tracking=1; - led=!led; - + pc.printf("current beat : %d \n\r",tracking); + if(tracking==1) { sn44tick.detach(); @@ -217,27 +213,27 @@ kick44tick.detach(); if(beat[0][1]==1) { - //pc.printf("1"); + pc.printf("1"); kick44tick.attach(&playkick,1.0 / 33075); } if(beat[1][1]==1) { - //pc.printf("2"); + pc.printf("2"); sn44tick.attach(&playsnare,1.0 / 33075); } if(beat[2][1]==1) { - //pc.printf("3"); + pc.printf("3"); cl44tick.attach(&playclap,1.0 /22050); } if(beat[3][1]==1) { - //pc.printf("4"); + pc.printf("4"); clhh44tick.attach(&playclhh,1.0 / 33075); } if(beat[4][1]==1) { - //pc.printf("5"); + pc.printf("5"); ophh44tick.attach(&playophh,1.0 / 33075); } @@ -252,27 +248,27 @@ kick44tick.detach(); if(beat[0][2]==1) { - //pc.printf("1"); + pc.printf("1"); kick44tick.attach(&playkick,1.0 / 33075); } if(beat[1][2]==1) { - //pc.printf("2"); + pc.printf("2"); sn44tick.attach(&playsnare,1.0 / 33075); } if(beat[2][2]==1) { - //pc.printf("3"); + pc.printf("3"); cl44tick.attach(&playclap,1.0 /22050); } if(beat[3][2]==1) { - //pc.printf("4"); + pc.printf("4"); clhh44tick.attach(&playclhh,1.0 / 33075); } if(beat[4][2]==1) { - //pc.printf("5"); + pc.printf("5"); ophh44tick.attach(&playophh,1.0 / 33075); } @@ -287,27 +283,27 @@ kick44tick.detach(); if(beat[0][3]==1) { - //pc.printf("1"); + pc.printf("1"); kick44tick.attach(&playkick,1.0 / 33075); } if(beat[1][3]==1) { - //pc.printf("2"); + pc.printf("2"); sn44tick.attach(&playsnare,1.0 / 33075); } if(beat[2][3]==1) { - //pc.printf("3"); + pc.printf("3"); cl44tick.attach(&playclap,1.0 /22050); } if(beat[3][3]==1) { - //pc.printf("4"); + pc.printf("4"); clhh44tick.attach(&playclhh,1.0 / 33075); } if(beat[4][3]==1) { - //pc.printf("5"); + pc.printf("5"); ophh44tick.attach(&playophh,1.0 / 33075); } @@ -322,27 +318,27 @@ kick44tick.detach(); if(beat[0][4]==1) { - //pc.printf("1"); + pc.printf("1"); kick44tick.attach(&playkick,1.0 / 33075); } if(beat[1][4]==1) { - //pc.printf("2"); + pc.printf("2"); sn44tick.attach(&playsnare,1.0 / 33075); } if(beat[2][4]==1) { - //pc.printf("3"); + pc.printf("3"); cl44tick.attach(&playclap,1.0 /22050); } if(beat[3][4]==1) { - //pc.printf("4"); + pc.printf("4"); clhh44tick.attach(&playclhh,1.0 / 33075); } if(beat[4][4]==1) { - //pc.printf("5"); + pc.printf("5"); ophh44tick.attach(&playophh,1.0 / 33075); } @@ -357,27 +353,27 @@ kick44tick.detach(); if(beat[0][5]==1) { - //pc.printf("1"); + pc.printf("1"); kick44tick.attach(&playkick,1.0 / 33075); } if(beat[1][5]==1) { - //pc.printf("2"); + pc.printf("2"); sn44tick.attach(&playsnare,1.0 / 33075); } if(beat[2][5]==1) { - //pc.printf("3"); + pc.printf("3"); cl44tick.attach(&playclap,1.0 /22050); } if(beat[3][5]==1) { - //pc.printf("4"); + pc.printf("4"); clhh44tick.attach(&playclhh,1.0 / 33075); } if(beat[4][5]==1) { - //pc.printf("5"); + pc.printf("5"); ophh44tick.attach(&playophh,1.0 / 33075); } @@ -390,29 +386,29 @@ clhh44tick.detach(); ophh44tick.detach(); kick44tick.detach(); - if(beat[0][0]==1) + if(beat[0][6]==1) { - //pc.printf("6"); + pc.printf("1"); kick44tick.attach(&playkick,1.0 / 33075); } - if(beat[1][0]==1) + if(beat[1][6]==1) { - //pc.printf("6"); + pc.printf("2"); sn44tick.attach(&playsnare,1.0 / 33075); } - if(beat[2][0]==1) + if(beat[2][6]==1) { - //pc.printf("6"); + pc.printf("3"); cl44tick.attach(&playclap,1.0 /22050); } - if(beat[3][0]==1) + if(beat[3][6]==1) { - //pc.printf("6"); + pc.printf("4"); clhh44tick.attach(&playclhh,1.0 / 33075); } - if(beat[4][0]==1) + if(beat[4][6]==1) { - //pc.printf("6"); + pc.printf("5"); ophh44tick.attach(&playophh,1.0 / 33075); } @@ -425,34 +421,43 @@ clhh44tick.detach(); ophh44tick.detach(); kick44tick.detach(); - if(beat[0][0]==1) + if(beat[0][7]==1) { - //pc.printf("7"); + pc.printf("1"); kick44tick.attach(&playkick,1.0 / 33075); } - if(beat[1][0]==1) + if(beat[1][7]==1) { - //pc.printf("7"); + pc.printf("2"); sn44tick.attach(&playsnare,1.0 / 33075); } - if(beat[2][0]==1) + if(beat[2][7]==1) { - //pc.printf("7"); + pc.printf("3"); cl44tick.attach(&playclap,1.0 /22050); } - if(beat[3][0]==1) + if(beat[3][7]==1) { - //pc.printf("7"); + pc.printf("4"); clhh44tick.attach(&playclhh,1.0 / 33075); } - if(beat[4][0]==1) + if(beat[4][7]==1) { - //pc.printf("7"); + pc.printf("5"); ophh44tick.attach(&playophh,1.0 / 33075); } } + if(tracking<8) + { + tracking=tracking+1; + } + else if(tracking==8) + { + tracking=1; + led=!led; + } } else if(checkplay==0)//led off @@ -618,16 +623,20 @@ void knob()//read analog { + - volume=(volumeknob.read()*100);//0to100 - tempo=(tempoknob.read()*100);//problematic******************************************** + volume=volumeknob.read();//0to100 + tempo=tempoknob.read();//problematic******************************************** - sprintf(tempostr,"%1.1f",tempo); - sprintf(volumechar,"%1.1f",volume); - pc.printf("tempo = %s \n\r",tempostr); //print ในuart ถูก - pc.printf("volume = %s\n\r",volumechar); - speed=floor(tempo); - speed=(60/speed)/2; + volume2=volume*100; + sprintf(volumechar,"%1.1f",volume2); + tempo2=60+(tempo*90); + speed=(60/tempo2)/2; + sprintf(tempostr,"%1.1f",speed); + pc.printf("speed = %1.3f\n\r",speed); + pc.printf("tempo =%1.1f\n\r",tempo2); + pc.printf("volume =%1.3f\n\r",volume); + pc.printf("volume =%1.1f percent\n\r",volume2); } @@ -654,7 +663,7 @@ sprintf(strtempo,"%s","Tempo "); lcd.SetTextColor(LCD_COLOR_BLACK); lcd.DisplayStringAt(24,LINE(1),(uint8_t*)strtempo,RIGHT_MODE); - sprintf(tempostr,"%1.1f",tempo); ////////////////////////////////////////////display tempo on lcd ไม่ถูก + sprintf(tempostr,"%1.1f",tempo2); ////////////////////////////////////////////display tempo on lcd ไม่ถูก lcd.SetTextColor(LCD_COLOR_BLACK); lcd.DisplayStringAt(24,LINE(2),(uint8_t*)tempostr,RIGHT_MODE);