Emg filter function script for a uni project. Made by Teun van der Molen

Dependencies:   HIDScope MODSERIAL mbed

Fork of frdm_EMG by Teun van der Molen

Revision:
8:54f0a76d35f4
Parent:
7:43f2f7039841
Child:
9:2b9240084724
--- a/main.cpp	Wed Sep 23 13:05:49 2015 +0000
+++ b/main.cpp	Wed Sep 23 14:51:13 2015 +0000
@@ -5,8 +5,12 @@
 HIDScope    scope(3);
 Ticker      scopeTimer;
 Ticker      biquadTicker;
-DigitalOut  light(LED1);
+DigitalOut  light(LED2);
+DigitalIn    knop(SW3);
 
+double c=5; //calibration value
+double n = 0; // counter for calibration
+bool calib = false; //changes into false when calibration is done (reset program for new calibration); 
 double v1=0, v2=0, u=0, y=0,     fy=0, fv1=0, fv2=0, fu=0;
 
 //const double b0 = 0.9999999999999999,b1 = 1.9999999999999998,b2 = 0.9999999999999999, a1 = 1.9999999999999998 ,a2 = 0.9999999999999998; //low-pass Fc = 50hz fs = 100hz
@@ -34,11 +38,21 @@
 // The data read and send function
 void scopeSend()
 {
-    scope.set(0,y);
+    scope.set(0,c);
     scope.set(1,fy);
-    scope.set(2,an_in);
+    scope.set(2,n);
    
     scope.send();
+    
+    while(calib == true and n <= 2000.00) {
+        
+        c = c + fy;
+    
+        n ++;
+        
+        }
+        
+        
 }
  
  void computeBiquad(){
@@ -62,21 +76,41 @@
 }
  
  
+ 
+
+ 
+ 
+ 
+ 
 int main()
 {
     light = 1;
+    
     // Attach the data read and send function at 1000 Hz
     scopeTimer.attach_us(&scopeSend, 1e5);   
+    //scopeTimer.attach_us(&calibrate, 1e5);
     biquadTicker.attach(&computeBiquad,0.0001f);
      //float i = 1;
     while(1) {
-      if (fy >=  0.12){
+      if (fy >=  c and calib == false){
           light = 0;
           }
-        else{
-            light =1;
+        
+      
+      else if (knop == 0){
+          light = 0;
+          calib = true;
+          c = 0;
+          n = 0;
+          wait(5);
+          light = 1;
+          calib = false;
+          c = c/n;
+         }
+          
+          
+      else{
+            light = 1;
             }
-      
-      
     }
 }
\ No newline at end of file