Measures EMG signal, filters them and puts on a led

Dependencies:   HIDScope MODSERIAL Math MovingAverage biquadFilter mbed

Fork of EMG by Tom Tom

Committer:
tomlankhorst
Date:
Thu Sep 22 08:36:00 2016 +0000
Revision:
19:2bf824669684
Parent:
18:21d8e7a81cf5
Child:
20:97059009a491
Two channel EMG @ 500 Hz

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vsluiter 0:32bb76391d89 1 #include "mbed.h"
vsluiter 11:ce72ec658a95 2 #include "HIDScope.h"
vsluiter 0:32bb76391d89 3
vsluiter 4:8b298dfada81 4 //Define objects
tomlankhorst 19:2bf824669684 5 AnalogIn emg0( A0 );
tomlankhorst 19:2bf824669684 6 AnalogIn emg1( A1 );
tomlankhorst 19:2bf824669684 7
tomlankhorst 14:f83354387756 8 Ticker sample_timer;
tomlankhorst 19:2bf824669684 9 HIDScope scope( 2 );
tomlankhorst 18:21d8e7a81cf5 10 DigitalOut led(LED1);
vsluiter 2:e314bb3b2d99 11
tomlankhorst 14:f83354387756 12 /** Sample function
tomlankhorst 14:f83354387756 13 * this function samples the emg and sends it to HIDScope
tomlankhorst 14:f83354387756 14 **/
tomlankhorst 14:f83354387756 15 void sample()
vsluiter 2:e314bb3b2d99 16 {
tomlankhorst 19:2bf824669684 17 /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */
tomlankhorst 19:2bf824669684 18 scope.set(0, emg0.read() );
tomlankhorst 19:2bf824669684 19 scope.set(1, emg1.read() );
tomlankhorst 19:2bf824669684 20 /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels)
tomlankhorst 19:2bf824669684 21 * Ensure that enough channels are available (HIDScope scope( 2 ))
tomlankhorst 14:f83354387756 22 /* Finally, send all channels to the PC at once */
vsluiter 11:ce72ec658a95 23 scope.send();
tomlankhorst 18:21d8e7a81cf5 24 /* To indicate that the function is working, the LED is toggled */
tomlankhorst 18:21d8e7a81cf5 25 led = !led;
vsluiter 2:e314bb3b2d99 26 }
vsluiter 0:32bb76391d89 27
vsluiter 0:32bb76391d89 28 int main()
tomlankhorst 19:2bf824669684 29 {
tomlankhorst 14:f83354387756 30 /**Attach the 'sample' function to the timer 'sample_timer'.
tomlankhorst 19:2bf824669684 31 * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz
vsluiter 4:8b298dfada81 32 */
tomlankhorst 19:2bf824669684 33 sample_timer.attach(&sample, 0.002);
tomlankhorst 15:0da764eea774 34
tomlankhorst 14:f83354387756 35 /*empty loop, sample() is executed periodically*/
tomlankhorst 15:0da764eea774 36 while(1) {}
vsluiter 0:32bb76391d89 37 }