script zover
Dependencies: HIDScope MODSERIAL mbed
main.cpp
- Committer:
- wiesdat
- Date:
- 2014-10-13
- Revision:
- 1:bc2db3bff4bb
- Parent:
- 0:bed29da02e8b
- Child:
- 2:620ff9f02d62
File content as of revision 1:bc2db3bff4bb:
#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 #define TSAMP 0.01 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; volatile bool looptimerflag; 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(); } void setlooptimerflag(void) { looptimerflag = true; } int main() { pc.baud(115200); timer.attach(setlooptimerflag,TSAMP); //timer.attach(scope,0.05); while(1) { while(!looptimerflag) looptimerflag = false; read(); y = filter(emg_value); viewer(); } }