penkich_percussion_2_NUCLEO

Dependencies:   mbed

Fork of penkich_test_percussion by kitac_mbed_WS

Files at this revision

API Documentation at this revision

Comitter:
penkich
Date:
Sun Aug 30 07:31:36 2015 +0000
Parent:
0:e363f64b5744
Commit message:
penkich_percussion_2_NUCLEO

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Aug 18 12:26:25 2015 +0000
+++ b/main.cpp	Sun Aug 30 07:31:36 2015 +0000
@@ -1,18 +1,18 @@
 #include "mbed.h"
 
-DigitalIn sw(dp9);
+AnalogIn sw(A0);
 Ticker timer;
-PwmOut speaker(dp18);
+PwmOut speaker(D5);
 Ticker envelope;
-PwmOut env(dp24);
+PwmOut env(D3);
 static int tms_per10=0; 
 
 void env_out(void){
-    float attack_ms =10;
-    float decay_ms = 10;
-    float sustain_ms = 200;
+    float attack_ms =5;
+    float decay_ms = 50;
+    float sustain_ms = 20;
     float sustain = 0.5;
-    float release_ms = 400;
+    float release_ms = 0;
 
     float out_level;
     tms_per10++;
@@ -26,7 +26,7 @@
     }else if(tms_per10 > attack_ms * 10){
         env.write(1.0f);
     }else{
-        out_level = 1.0/attack_ms * tms_per10;
+        out_level = 1.0f/attack_ms * tms_per10;
         env.write(out_level);
     }
 }
@@ -39,13 +39,14 @@
 int main()
 {
     while(1){
-        if (sw ==0){
+        if (sw >=0.3f){
             tms_per10=0; 
             speaker.period_us(10);
             env.period_us(10);
             timer.attach_us(&sound_out,100); //10kHz
             envelope.attach_us(&env_out,100); //10kHz
         }
-    wait(0.01f);
+        wait(0.01f);
+    //envelope.detach();
     }
 }
\ No newline at end of file