test publish

Dependencies:   mbed GroveEarbudSensor

Revision:
12:a56f9fb318de
Parent:
11:e9d48f0a6b3e
--- a/main.cpp	Thu Apr 14 12:18:49 2016 +0000
+++ b/main.cpp	Thu Apr 14 13:06:29 2016 +0000
@@ -1,75 +1,15 @@
 #include "mbed.h"
-#include "GroveEarbudSensor.h"
-#include "GypsyScale.h"
-#include "MajorScale.h"
-#include "Speaker.h"
-#include "MelodyGenerator.h"
-#include "Notes.h"
-#include "GSRSensor.h"
-#include <vector>
-
-#define NBGSRVALUE 20
+#include "Application.h"
 
 using namespace std;
 
 InterruptIn earSensorPin(p5);
 AnalogIn GSRPin(p15);
-//DigitalOut led(LED1);
 PwmOut speakerPin(p21);
 
 int main()
 {
-    GroveEarbudSensor earbud(&earSensorPin);
-    Speaker speaker(&speakerPin);
-    MelodyGenerator melodyGen;
-    GSRSensor GSRSens(&GSRPin);
-    
-    MajorScale scale1(SOL_4);
-    GypsyScale scale2(MI_4);
-    
-    printf("Initialization.. waiting 14s");
-    fflush(stdout);
-    wait(4); // Time for GSR measure to stabilize
-    
-    float sumGSR, sumHR = 0.0;
-    float thresholdHR, thresholdGSR = 0.0;
-    for(int i = 0 ; i<NBGSRVALUE ; i++){
-        sumGSR += GSRSens.getGSRValue();
-        sumHR += earbud.getHeartRate();
-        wait(0.5);
-             
-    }
-    thresholdGSR = sumGSR/NBGSRVALUE;
-    thresholdHR = sumHR/NBGSRVALUE;
-    
-    vector<Notes>* melo;
-    float heartRate, measureGSR;
-    while(true) {
-        
-        heartRate = earbud.getHeartRate();
-        measureGSR = GSRSens.getGSRValue();
-        printf("\r\nHeartrate : %0.0f (nominal : %0.3f) \r\nGSR       : %0.4f (nominal : %0.4f) \r\n", heartRate, thresholdHR, measureGSR, thresholdGSR); // for debug purpose
-
-        if(heartRate <30) {
-            speaker.play(SILENCE);
-            heartRate = earbud.getHeartRate();
-            wait(1);
-        } else {
-            if (measureGSR < thresholdGSR){
-                melo = melodyGen.getMeasure(scale1);
-                printf("\tMajor scale\r\n");
-            }
-            else {
-                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));
-            }
-        }
-
-        
-    }
+    Application App = Application(&earSensorPin, &GSRPin, &speakerPin);
+    App.Init();
+    App.Run();
 }