Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BiQuad4th_order Biquad HIDScope MODSERIAL biquadFilter mbed
main.cpp
00001 #include "mbed.h" 00002 #include "MODSERIAL.h" 00003 #include "BiQuad.h" 00004 #include "BiQuad4.h" 00005 #include "FilterDesign.h" 00006 #include "FilterDesign2.h" 00007 #include "HIDScope.h" 00008 MODSERIAL pc(USBTX, USBRX); //makes sure the computer is hooked up 00009 Ticker sample; 00010 00011 AnalogIn emg1_raw(A0); 00012 AnalogIn emg2_raw(A1); 00013 DigitalOut led(LED_RED); 00014 00015 //global variables 00016 double emg1_cal = 0.00000; //measured value of the first emg 00017 double emg2_cal = 0.00000; //measured value of the second emg 00018 double EMG_calibrated_max_1 = 0.00000; //final calibration value of EMG1 00019 double EMG_calibrated_max_2 = 0.00000; //final calibration value of EMG2 00020 00021 void ReadEMG() 00022 { 00023 emg1_cal = FilterDesign(emg1_raw.read()); 00024 emg2_cal = FilterDesign2(emg2_raw.read()); 00025 } 00026 00027 void EMG_calibration() 00028 { 00029 for (int i = 0; i <= 10; i++) //10 measuring points 00030 { 00031 if (emg1_cal > EMG_calibrated_max_1){ 00032 EMG_calibrated_max_1 = emg1_cal;} 00033 00034 if (emg2_cal > EMG_calibrated_max_2){ 00035 EMG_calibrated_max_2 = emg2_cal;} 00036 00037 pc.printf("EMG1 = %f, EMG2 = %f \r\n",EMG_calibrated_max_1,EMG_calibrated_max_2); 00038 wait(0.5f); 00039 } 00040 } 00041 00042 00043 00044 int main(){ 00045 pc.baud(115200); 00046 // Attach the 'ReadEMG' function to the timer 'sample'. Frequency is 5 Hz. 00047 sample.attach(&ReadEMG, 0.2f); 00048 00049 while (true) { 00050 led = 0; 00051 EMG_calibration(); 00052 led = 1; 00053 pc.printf("Final: EMG1 = %f, EMG2 = %f \r\n",EMG_calibrated_max_1,EMG_calibrated_max_2); 00054 } 00055 }
Generated on Sun Jul 24 2022 09:02:59 by
