test publish
Dependencies: mbed GroveEarbudSensor
Revision 13:879d678baf64, committed 2016-04-14
- Comitter:
- age2pierre
- Date:
- Thu Apr 14 14:01:28 2016 +0000
- Parent:
- 12:a56f9fb318de
- Commit message:
- Added Ticker
Changed in this revision
Application.cpp | Show annotated file Show diff for this revision Revisions of this file |
Application.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r a56f9fb318de -r 879d678baf64 Application.cpp --- 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
diff -r a56f9fb318de -r 879d678baf64 Application.h --- a/Application.h Thu Apr 14 13:06:29 2016 +0000 +++ b/Application.h Thu Apr 14 14:01:28 2016 +0000 @@ -21,6 +21,9 @@ GSRSensor GSRSens; float thresholdHR; float thresholdGSR; + Ticker timerNote; + void playMeasure(); + vector<Notes>* melo; public : Application(InterruptIn* earSensorPin, AnalogIn* GSRPin, PwmOut* speakerPin); void Init();