the emg filtering part of the program

Dependencies:   HIDScope biquadFilter mbed MODSERIAL

Fork of EMG by Tom Tom

Revision:
33:fcd4568f1c86
Parent:
32:e1e5f03e9faf
Child:
35:4905144c1123
--- a/main.cpp	Tue Oct 25 10:47:29 2016 +0000
+++ b/main.cpp	Tue Oct 25 12:50:55 2016 +0000
@@ -24,16 +24,16 @@
 volatile bool buttonflag = false;
 volatile bool newcase = false;
 
-double threshold = 0.11;
+double threshold = 0.04;
 double samplefreq=0.002;
 double emg02;
 double emg12;
 double emg22;
 double ref_x=0.000;
 double ref_y=0.000;
-double speed=0.2;
+double speed=0.00002;
 const int negative=-1;
-//char key;
+char key;
 
 
 // create a variable called 'state', define it
@@ -93,6 +93,16 @@
 {
     states myoldstate=mystate;
 
+   // key=pc.getcNb();
+
+    if (pc.readable()==1) {
+        key=pc.getc();
+        speed=0.000326;
+    } else {
+        key ='p';
+        speed=0.00002;
+    }
+
     /* Read the emg signals and filter it*/
 
     scope.set(0, emg1.read());    //original signal
@@ -111,29 +121,30 @@
      *   Finally, send all channels to the PC at once */
     scope.send();
 
-    if (emg02>threshold&&emg12>threshold&&emg22>threshold ) {
+
+    if (emg02>threshold&&emg12>threshold&&emg22>threshold || key=='d') {
         mystate = STATE_XY_NEG;
         ref_x=ref_x+speed*negative;
         ref_y=ref_y+speed*negative;
 
-    } else if (emg02>threshold&&emg12>threshold ) {
+    } else if (emg02>threshold&&emg12>threshold || key == 'a' ) {
         mystate = STATE_X_NEG;
         ref_x=ref_x+speed*negative;
 
-    } else if (emg02>threshold&&emg22>threshold) {
+    } else if (emg02>threshold&&emg22>threshold || key == 's') {
         mystate = STATE_Y_NEG;
         ref_y=ref_y+speed*negative;
 
-    } else if (emg12>threshold&&emg22>threshold ) {
+    } else if (emg12>threshold&&emg22>threshold || key == 'e' ) {
         mystate = STATE_XY;
         ref_x=ref_x+speed;
         ref_y=ref_y+speed;
 
-    } else if (emg12>threshold ) {
+    } else if (emg12>threshold || key == 'q' ) {
         mystate = STATE_X;
         ref_x=ref_x+speed;
 
-    } else if (emg22>threshold ) {
+    } else if (emg22>threshold || key == 'w') {
         mystate = STATE_Y;
         ref_y=ref_y+speed;
     } else {
@@ -214,7 +225,7 @@
         if (sampletimer==true) {
             //sample(mystate);
             sample(mystate);
-            print_state();
+          //  print_state();
             sampletimer = false;
         }
     }