![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
script zover
Dependencies: HIDScope MODSERIAL mbed
Diff: main.cpp
- Revision:
- 0:bed29da02e8b
- Child:
- 1:bc2db3bff4bb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Oct 13 10:44:50 2014 +0000 @@ -0,0 +1,51 @@ +#include "mbed.h" +#include "MODSERIAL.h" +#include "HIDScope.h" + +#define A1HP -1.999214978283642 +#define A0HP 0.999214978283642 +#define B1HP -1.943446330323158 +#define B0HP 0.945001709500376 + +AnalogIn emg0(PTB1); +MODSERIAL pc(USBTX,USBRX); +HIDScope scope(2); +Ticker timer; +float filter(float); +float emg_value; +static float y,x1=0,y1=0,x2=0,y2=0; + + + +void read() +{ + emg_value=emg0.read_u16(); +} + +float filter(float emg0_value) +{ + y = y1*B1HP-y2*B0HP-x1*A1HP+x2*A0HP; + x2 = x1; + x1 = emg0_value; + y2 = y1; + y1 = y; + return y; +} + +void viewer() +{ + scope.set(0,emg_value); + scope.set(1,y); + scope.send(); +} + +int main() +{ + pc.baud(115200); + timer.attach(read,0.05); + timer.attach(viewer,0.05); +//timer.attach(scope,0.05); + while(1) { + y = filter(emg_value); + } +} \ No newline at end of file