Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 3:b7df72682b81
- Parent:
- 2:07cef563acdf
- Child:
- 4:9b7ea5528a5c
diff -r 07cef563acdf -r b7df72682b81 main.cpp --- a/main.cpp Mon Mar 30 15:03:36 2020 +0000 +++ b/main.cpp Wed Apr 01 16:25:32 2020 +0000 @@ -36,7 +36,7 @@ const char SYNTH[5] = {'S','Y','N','T','H'}; //Global Variables -volatile int o[4096]; +volatile unsigned short o[4096]; int main() { @@ -46,17 +46,9 @@ pad.leds_on(); sinspeak(); pad.leds_off(); - printf("Waiting for button press \n"); - while (1) { - int a = pad.A_pressed(); - if (pad.A_pressed()==true) { - printf("A Pressed \n"); - sinspeak(); - } - //wait_ms(10); - printf("A= %d \n", a); + for (int rep=0; rep<10; rep++) { + sinspeak(); } - // squareWave(); } @@ -65,8 +57,8 @@ { pad.init(); //initiate Gamepad pad.leds_on(); //turn LEDS on to show starting up + printf("Initialising Pad\n"); pad.play_melody(8,notes,duration,108,0); //play startup tune - printf("Initialising Pad\n"); lcd.init(); //intitates screen lcd.clear(); lcd.setContrast(0.4f); //contrast setting @@ -87,8 +79,6 @@ } - - void wavetable() { int samples= 4096; @@ -102,54 +92,41 @@ float ifl=0.0; //creates fl type incramenter for (int i=0; i<4096; i++) { - sinfl[i] = 6553500.0f*sin(2.0f*PI*(ifl/4096.0f)); - sinf[i] = sinfl[i]/100.0f; - o[i]= sinf[i]+32767; //generates wave table - //printf("o[i]= %d",o[i], "\n"); // Used for Debug + sinfl[i] = 65536.0f*sin(2.0f*PI*(ifl/4096.0f)); + sinf[i] = sinfl[i]; + o[i]= sinf[i]+32767; //generates wave table in uint + // printf("o[i]= %u \n", o[i]); // Used for Debug ifl=i+1.0f; } pad.leds_off(); } + + void sinspeak () { - float f=440.0; float f1=440.0; - float f2=1.0; float i=0; - //int i1=0; - float i2=0; - int v=0; + unsigned short v=0; int inc=0; pad.reset_buttons(); f1 = pad.read_pot1(); - //f2 = pad.read_pot2(); - f1 = 440.0f+440.0f*f; - f2 = 5.0f*f2; - printf("f1= %f \n",f1); // Used for Debug - printf("f2= %f \n",f2); + f1 = 440.0f+440.0f*f1; + //printf("f1= %f \n",f1); // Used for Debug while (inc<3000) { int inti = i; v = o[inti]; - printf("OUTPUT: %d \n", v); - //pad.write_u16(v); - wait_us(190); //200us but 150 for delay (uncalculated) - - i2 = i2 + ((4096*f2)/5000); //i2+((samples*f)*Ts) - if (i2>=4096) { - i2=i2-4096; - } - int inti2 = i2; - int x = (o[inti2]/6554)-5; //(amp/6554)-offset =sin10f - float xfloat = x; - printf("x= %d \n", x); // Used for Debug - f = f1 + xfloat; - - i = i + ((4096.0f*f)/5000.0f); //i+((samples*f)*Ts) + //printf("OUTPUT: %u \n", v); + pad.write_u16(v); + wait_us(230); //fs= 4k Ts=250us + + i = i + ((4096.0f*f1)/4000.0f); //i+((samples*f)*Ts) if (i>=4096.0f) { i=i-4096.0f; + } + else { + wait_us(3); } - inc++; } }