kapotte printf

Dependencies:   HIDScope biquadFilter mbed

Files at this revision

API Documentation at this revision

Comitter:
Joost38H
Date:
Mon Oct 23 09:06:57 2017 +0000
Parent:
1:4d7097e583e0
Commit message:
kapotte printf

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Oct 23 07:31:18 2017 +0000
+++ b/main.cpp	Mon Oct 23 09:06:57 2017 +0000
@@ -3,7 +3,9 @@
 #include "BiQuad.h"
 #include "math.h"
 
-Serial      pc(USBTX, USBRX);
+
+Serial pc(USBTX, USBRX);
+
 
 //Defining all in- and outputs
 //EMG input
@@ -73,6 +75,7 @@
     emgBRrectified = fabs(emgBRfiltered);            //Rectification
     emgBRcomplete = bqLow1.step(emgBRrectified);     //Low-pass
     
+    
    
     emgBLfiltered = bqChain2.step( emgBL.read() );    //Notch+High-pass
     emgBLrectified = fabs( emgBLfiltered );           //Rectification
@@ -89,8 +92,45 @@
     scope.send();
     /* To indicate that the function is working, the LED is toggled */
     led_B = !led_B;
+    
+    
 }
 
+double numsamples = 500;
+double emgBRarray[500];
+double emgBRsum;
+double emgBRmeanMVC;
+double thresholdBR;
+
+double getThresholdBR()
+{
+    for (int i=0; i<numsamples; i++) {
+        emgBRarray[i] = emgBRcomplete;
+        emgBRsum = emgBRsum + emgBRarray[i];
+        }
+    
+    emgBRmeanMVC = emgBRsum / numsamples;
+    
+    thresholdBR = emgBRmeanMVC * 0.3;
+    return thresholdBR;
+}
+    
+double getThresholdBL()
+{
+    double numsamples = 500;
+    double emgBLarray[500];
+    double emgBLsum;
+    for (int i=0; i<numsamples; i++) {
+        emgBLarray[i] = emgBLcomplete;
+        emgBLsum = emgBLsum + emgBLarray[i];
+        }
+    
+    double emgBLmeanMVC = emgBLsum / numsamples;
+    
+    double thresholdBL = emgBLmeanMVC * 0.3;
+    return thresholdBL;
+}
+    
 
 // Function to make the BiQuadChain for the Notch and High pass filter for all three filters    
 void getbqChain()
@@ -103,7 +143,7 @@
 // Function to check if the threshold is met, with LED feedback for the user
 void ThresholdReached()
 {
-    if (emgBRcomplete > threshold) 
+    if (emgBRcomplete > thresholdBR) 
     {
         led_G = 0;
         led_R = 1;
@@ -125,8 +165,7 @@
         }
         
 }
-        
-    
+  
 
 int main()
 {   
@@ -134,9 +173,11 @@
     this ensures that 'sample' is executed every 0.002 seconds, to get a 
     sample frequency of 500 Hz
     */
-    
+    pc.baud(115200);
     getbqChain();
     sample_timer.attach(&EMG_sample, 0.002);
+    thresholdBR = getThresholdBR();
+    pc.printf("Threshold is %f.2\n", threshold);
     threshold_timer.attach(&ThresholdReached, 0.002);