the emg filtering part of the program
Dependencies: HIDScope biquadFilter mbed MODSERIAL
Fork of EMG by
Diff: main.cpp
- Revision:
- 28:3b1b29193851
- Parent:
- 27:1ff7fa636f1c
- Child:
- 29:ac08c1a32c54
--- a/main.cpp Fri Oct 21 13:32:25 2016 +0000 +++ b/main.cpp Mon Oct 24 08:47:19 2016 +0000 @@ -20,6 +20,7 @@ volatile bool sampletimer = false; volatile bool buttonflag = false; volatile bool newcase = false; +volatile bool newcaseprint = false; double threshold = 0.04; double samplefreq=0.002; @@ -29,8 +30,11 @@ double ref_x=0.000; double ref_y=0.000; +// create a variable called 'state', define it typedef enum { STATE_CALIBRATION, STATE_PAUZE, STATE_X, STATE_X_NEG, STATE_Y, STATE_Y_NEG, STATE_XY, STATE_XY_NEG } states; +states mystate = STATE_PAUZE; + BiQuadChain bqc11; BiQuadChain bqc13; BiQuadChain bqc21; @@ -160,9 +164,14 @@ if (myoldstate==mystate) { newcase=false; + newcaseprint=false; + } else { newcase=true; + newcaseprint=true; + } + sampletimer = false; } @@ -219,8 +228,10 @@ } if (myoldstate==mystate) { + newcaseprint=false; newcase=false; } else { + newcaseprint=true; newcase=true; } @@ -229,7 +240,7 @@ void change_x(int direction) { - ref_x=ref_x+0.1*direction; + ref_x=ref_x+0.0002*direction; } @@ -250,13 +261,45 @@ } +void print_state(states mystate) +{ + // switch, case + if (newcaseprint==true) { + switch (mystate) { + case STATE_CALIBRATION : { // calibration + pc.printf("calibration\n\r"); + break; + } + case STATE_X : // run + pc.printf("X\n\r"); + break; + case STATE_X_NEG : // run + pc.printf("Xneg\n\r"); + break; + case STATE_Y : // execute mode 1 + pc.printf("Y\n\r"); + break; + case STATE_Y_NEG : // execute mode 1 + pc.printf("Yneg\n\r"); + break; + case STATE_XY : // execute mode 2 + pc.printf("XY\n\r"); + break; + case STATE_XY_NEG : // execute mode 2 + pc.printf("XYneg\n\r"); + break; + case STATE_PAUZE : // default + pc.printf("PAUZE\n\r"); + break; + } + } + +} + int main() { pc.baud(115200); - // create a variable called 'state', define it - states mystate = STATE_PAUZE; - //de biquad chains instellen bqc11.add( &bq111 ).add( &bq112 ).add( &bq113 ).add( &bq121 ); bqc13.add( &bq131); @@ -276,67 +319,7 @@ if (sampletimer==true) { //sample(mystate); sample_button(mystate); + print_state(mystate); } - - // switch, case - switch (mystate) { - case STATE_CALIBRATION : { // calibration - pc.printf("calibration\n\r"); - while (button_calibrate==0) {} - newcase=false; - buttonflag=false; - break; - } - case STATE_X : // run - if (newcase==true) { - pc.printf("X\n\r"); - newcase=false; - change_x(1); - } - - break; - case STATE_X_NEG : // run - if (newcase==true) { - pc.printf("Xneg\n\r"); - newcase=false; - change_x(-1); - } - break; - case STATE_Y : // execute mode 1 - if (newcase==true) { - pc.printf("Y\n\r"); - newcase=false; - change_y(1); - } - break; - case STATE_Y_NEG : // execute mode 1 - if (newcase==true) { - pc.printf("Yneg\n\r"); - newcase=false; - change_y(-1); - } - break; - case STATE_XY : // execute mode 2 - if (newcase==true) { - pc.printf("XY\n\r"); - newcase=false; - change_xy(1); - } - break; - case STATE_XY_NEG : // execute mode 2 - if (newcase==true) { - pc.printf("XYneg\n\r"); - newcase=false; - change_xy(-1); - } - break; - case STATE_PAUZE : // default - if (newcase==true) { - pc.printf("PAUZE\n\r"); - newcase=false; - } - break; - } - } } \ No newline at end of file