the emg filtering part of the program

Dependencies:   HIDScope biquadFilter mbed MODSERIAL

Fork of EMG by Tom Tom

Revision:
22:f38a15e851d2
Parent:
21:3aecd735319d
Child:
23:54d28f9eef53
--- a/main.cpp	Tue Oct 18 15:29:45 2016 +0000
+++ b/main.cpp	Wed Oct 19 19:33:25 2016 +0000
@@ -1,6 +1,7 @@
 #include "mbed.h"
 #include "HIDScope.h"
 #include "BiQuad.h"
+#include "MODSERIAL.h"
 
 //Define objects
 AnalogIn    emg1( A0 );
@@ -9,8 +10,12 @@
 
 Ticker      sample_timer;
 HIDScope    scope( 6 );
+MODSERIAL pc(USBTX, USBRX);
 DigitalOut  led(LED1);
 
+volatile bool sampletimer = false;
+
+
 BiQuadChain bqc11;
 BiQuadChain bqc13;
 BiQuadChain bqc21;
@@ -49,10 +54,17 @@
 /*  low pass filter*/
 BiQuad bq331( 3.91302e-05, 7.82604e-05, 3.91302e-05, -1.98223e+00, 9.82385e-01 );
 
+
+void sampleflag()
+{
+    sampletimer=true;
+}
+
+
 void sample()
 {
     /* Read the emg signals and filter it*/
-    
+
     scope.set(0, emg1.read());    //original signal
     double emg02=bqc13.step(fabs(bqc11.step(emg1.read())));
     scope.set(1, emg02);
@@ -64,16 +76,24 @@
     scope.set(4, emg3.read());    //original signal
     double emg22=bqc33.step(fabs(bqc31.step(emg3.read())));
     scope.set(5, emg22);
-
+    //pc.printf("Hello World!\n");
     /*   Ensure that enough channels are available (HIDScope scope( 2 ))
      *   Finally, send all channels to the PC at once */
     scope.send();
     /*   To indicate that the function is working, the LED is toggled */
     led = !led;
+    if (emg02>0.08||emg12>0.08||emg22>0.08) {
+        pc.printf("het werkt\n");
+    } else {
+        pc.printf("het werkt niet\n");
+    }
+    sampletimer = false;
 }
 
 int main()
 {
+    pc.baud(115200);
+
     //de biquad chains instellen
     bqc11.add( &bq111 ).add( &bq112 ).add( &bq113 ).add( &bq121 );
     bqc13.add( &bq131);
@@ -84,8 +104,12 @@
     /*Attach the 'sample' function to the timer 'sample_timer'.
       this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz
     */
-    sample_timer.attach(&sample, 0.002);
+    sample_timer.attach(&sampleflag, 0.002);
 
-    /* empty loop, sample() is executed periodically*/
-    while(1) {}
+    while(1) {
+        if (sampletimer==true) {
+            sample();
+
+        }
+    }
 }
\ No newline at end of file