test publish

Dependencies:   mbed GroveEarbudSensor

Revision:
13:879d678baf64
Parent:
12:a56f9fb318de
--- a/Application.cpp	Thu Apr 14 13:06:29 2016 +0000
+++ b/Application.cpp	Thu Apr 14 14:01:28 2016 +0000
@@ -11,7 +11,11 @@
     printf("Initialization.. waiting 14s");
     fflush(stdout);
     wait(4); // Time for GSR measure to stabilize
-
+    
+    /*
+    * Get #NBGSR measure of GSR and Heartrate  each 0.5 s 
+    * in order to establish nominal threshold
+    */
     float sumGSR, sumHR = 0.0;
     for(int i = 0 ; i<NBGSRVALUE ; i++) {
         sumGSR += GSRSens.getGSRValue();
@@ -29,7 +33,6 @@
     MelodyGenerator melodyGen;
     MajorScale scale1(SOL_4);
     GypsyScale scale2(MI_4);
-    vector<Notes>* melo;
     float heartRate, measureGSR;
 
     while(true) {
@@ -50,11 +53,21 @@
                 melo = melodyGen.getMeasure(scale2);
                 printf("\tGypsy scale\r\n");
             }
-
-            for(vector<Notes>::iterator it = melo->begin(); it != melo->end(); ++it) {
-                speaker.play(*it);
-                wait( 0.3 - ((heartRate - thresholdHR) * 0.0015));
-            }
+            
+            timerNote.attach(this, &Application::playMeasure, 0.3 - ((heartRate - thresholdHR) * 0.0015));
         }
     }
+}
+
+void Application::playMeasure()
+{
+    static int it = 0;
+    if(it < melo->size()) {
+        speaker.play((*melo)[it]);
+        ++it;
+    }
+    else {
+        it = 0;
+        timerNote.detach();
+    }
 }
\ No newline at end of file