Dependencies: mbed HIDScope biquadFilter
main.cpp
- Committer:
- hidde1104
- Date:
- 2019-10-21
- Revision:
- 27:c53dd84c38aa
- Parent:
- 21:48b40b82d195
- Child:
- 28:4eaf5990a7b3
File content as of revision 27:c53dd84c38aa:
#include "mbed.h" #include "HIDScope.h" #include "BiQuad.h" Serial pc(USBTX, USBRX); InterruptIn but1(PTC6); BiQuad bq1 (0.881889334678067, -1.76377866935613, 0.8818893346780671, -1.77069673005903, 0.797707797506027); BiQuad bq2 (0.000198358203463849, 0.000396716406927699, 0.000198358203463849, -1.96262073248799, 0.963423352820821); BiQuadChain bqc; //Define objects AnalogIn emg0( A0 ); AnalogIn emg1( A1 ); Ticker sample_timer; Ticker calibration_timer; HIDScope scope( 3 ); DigitalOut led(LED2); /** Sample function * this function samples the emg and sends it to HIDScope **/ float filter_value; void sample() { /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */ float emg0_value = emg0.read(); float emg1_value = emg1.read(); float filter_value = fabs(bq2.step(fabs(bq1.step(emg0_value - emg1_value)))); //scope.set(0, emg0.read() ); //scope.set(1, emg1.read() ); //scope.set(2, filter_value); /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels) * 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; } const int length = 1000; int i; float sample_array[length] = {}; void calibration() { i = 0; while (i < (length-1)) { sample(); pc.printf("I can reach this point\r\n"); sample_array[i] = filter_value; pc.printf("The filter_value is %f\r\n",filter_value); i++; wait(0.001); } } int main() { pc.baud(115200); pc.printf("Running main"); bqc.add( &bq1); /**Attach the 'sample' function to the timer 'sample_timer'. * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz */ calibration(); sample_timer.attach(&sample, 0.001); /*empty loop, sample() is executed periodically*/ while(1) {} }