the emg filtering part of the program
Dependencies: HIDScope biquadFilter mbed MODSERIAL
Fork of EMG by
Diff: main.cpp
- Revision:
- 24:01b4b51b5dc6
- Parent:
- 23:54d28f9eef53
- Child:
- 25:1a71424b05ff
diff -r 54d28f9eef53 -r 01b4b51b5dc6 main.cpp --- a/main.cpp Wed Oct 19 20:56:47 2016 +0000 +++ b/main.cpp Thu Oct 20 08:26:41 2016 +0000 @@ -5,6 +5,8 @@ #include <string.h> //Define objects + +InterruptIn button_calibrate(PTA4); AnalogIn emg1( A0 ); AnalogIn emg2( A1 ); AnalogIn emg3( A2 ); @@ -15,6 +17,7 @@ DigitalOut led(LED1); volatile bool sampletimer = false; +volatile bool buttonflag = false; double threshold = 0.04; double samplefreq=0.002; @@ -64,6 +67,10 @@ sampletimer=true; } +void buttonflag_go() +{ + buttonflag=true; +} void sample(states &mystate) { @@ -89,28 +96,32 @@ led = !led; if (emg02>threshold) { if (emg12>threshold&&emg22>threshold) { - mystate = STATE_XY_NEG; + mystate = STATE_XY_NEG; } else if (emg12>threshold) { - mystate = STATE_X_NEG; + mystate = STATE_X_NEG; } else if (emg22>threshold) { - mystate = STATE_Y_NEG; + mystate = STATE_Y_NEG; } else { - mystate = STATE_PAUZE; + mystate = STATE_PAUZE; } } else { if (emg12>threshold&&emg22>threshold) { - mystate = STATE_XY; + mystate = STATE_XY; } else if (emg12>threshold) { - mystate = STATE_X; + mystate = STATE_X; } else if (emg22>threshold) { - mystate = STATE_Y; + mystate = STATE_Y; } else { - mystate = STATE_PAUZE; + mystate = STATE_PAUZE; } } + if (buttonflag==true) { + mystate = STATE_CALIBRATION; + } + sampletimer = false; } @@ -119,7 +130,7 @@ pc.baud(115200); // create a variable called 'state', define it - states mystate = STATE_CALIBRATION; + states mystate = STATE_PAUZE; //de biquad chains instellen bqc11.add( &bq111 ).add( &bq112 ).add( &bq113 ).add( &bq121 ); @@ -132,6 +143,8 @@ this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz */ sample_timer.attach(&sampleflag, samplefreq); + button_calibrate.fall(&buttonflag_go); + while(1) { if (sampletimer==true) { @@ -141,7 +154,8 @@ switch (mystate) { case STATE_CALIBRATION : // calibration pc.printf("calibration"); - wait(0.5f); + while (button_calibrate==0) {} + buttonflag=false; break; case STATE_X : // run pc.printf("X");