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.
main.cpp
- Committer:
- MatthewMaat
- Date:
- 2019-10-11
- Revision:
- 21:4183ea24a735
- Parent:
- 20:97059009a491
File content as of revision 21:4183ea24a735:
#include "mbed.h" #include "HIDScope.h" #include <math.h> //Define objects AnalogIn emg0( A0 ); AnalogIn emg1( A1 ); Ticker sample_timer; HIDScope scope( 2 ); DigitalOut led(LED1); /** Sample function * this function samples the emg and sends it to HIDScope **/ void sample() { static int count=0; static float RMS_value=0; static float HighPass_value=0; count+=1; static float RMS[150]; static float HighPass[30]; float I1; float If; I1=emg0.read(); //read signal HighPass_value+=(I1-HighPass[count%30])/30.0; HighPass[count%30]=I1; If=pow(I1-HighPass_value,2.0f); // Highpass-filtered value squared RMS_value+=(If-RMS[count%150])/150.0; RMS[count%150]=If; /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */ scope.set(0, sqrt(RMS_value) ); // send root mean squared scope.set(1, emg0.read() ); /* 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; } int main() { /**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); /*empty loop, sample() is executed periodically*/ while(1) {} }