to send emg signal to motor with test programm
Dependencies: HIDScope biquadFilter mbed
Fork of EMGvoorjan by
Diff: main.cpp
- Revision:
- 24:fe3825337233
- Parent:
- 23:b5a09f96c2d7
- Child:
- 25:9c2fc98da6b3
diff -r b5a09f96c2d7 -r fe3825337233 main.cpp --- a/main.cpp Tue Oct 24 08:55:02 2017 +0000 +++ b/main.cpp Tue Oct 24 10:03:16 2017 +0000 @@ -3,17 +3,26 @@ #include "BiQuad.h" #include "math.h" + //Define objects AnalogIn emg0( A0 ); AnalogIn emg1( A1 ); Ticker sample_timer; -HIDScope scope( 2 ); +HIDScope scope( 3 ); DigitalOut led(LED1); /** Sample function * this function samples the emg and sends it to HIDScope **/ + + double a1 = 0; + double a2 = 0; + double a3 = 0; + double a4 = 0; + double a5 = 0; + + void sample() { /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */ @@ -37,10 +46,22 @@ void emgSample() { -double emgFiltered = bqc.step( emg.read() ); -double emgabs = abs(emgFiltered); -scope.set(0, emgFiltered ); -scope.set(1, emgabs ); + double emgFiltered = bqc.step( emg.read() ); + double emgabs = abs(emgFiltered); + scope.set(0, emgFiltered ); + scope.set(1, emgabs ); + + + a5 = a4; + a4 = a3; + a3 = a2; + a2 = a1; + a1 = emgabs; + + double moving = a1 + a2 + a3 + a4 + a5; + double movmean = moving/5; + scope.set(2, movmean ); + scope.send(); }