test publish
Dependencies: mbed GroveEarbudSensor
main.cpp
- Committer:
- antoineA
- Date:
- 2016-04-14
- Revision:
- 11:e9d48f0a6b3e
- Parent:
- 10:af58557a4d6c
- Child:
- 12:a56f9fb318de
File content as of revision 11:e9d48f0a6b3e:
#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 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)); } } } }