met printstatements 1

Dependencies:   HIDScope MODSERIAL PID QEI biquadFilter mbed

Fork of EMG_5 by Ralph Gerlings

main.cpp

Committer:
relvorelvo
Date:
2016-11-02
Revision:
22:68ab712b62b2
Parent:
21:136a1ab8163c
Child:
23:e5db011bd410

File content as of revision 22:68ab712b62b2:

#include "mbed.h"
#include "HIDScope.h"
#include "BiQuad.h"
#include "MODSERIAL.h"

//Define objects
AnalogIn    emg1_in( A0 );
AnalogIn    emg2_in( A1 );

Ticker      sample_timer;
HIDScope    scope( 3 );
DigitalOut  red(LED_RED);
DigitalOut  blue(LED_BLUE);
DigitalOut  green(LED_GREEN);
DigitalOut  emg1_out( D8 );
DigitalOut  emg2_out( D9 );
MODSERIAL   pc(USBTX, USBRX);


// EMG variables
double emg1;
double emg1highfilter;
double emg1notchfilter;
double emg1abs;
double emg1lowfilter;
double emgpeak;

double emg2;
double emg2highfilter;
double emg2notchfilter;
double emg2abs;
double emg2lowfilter;

// Filter settings
BiQuad filterhigh(9.704e-01,-1.9408,9.704e-01,-1.9389,9.427e-01);
BiQuad filternotch(9.495e-01,-1.8062,9.495e-01,-1.8062,8.992e-01);
BiQuad filterlow(1.439e-02,2.794e-02,1.397e-02,-1.7229,7.788e-01);
BiQuad filterpeak(1.0878,-1.950,8.771e-01,-1.95032,9.5499e-01);

// Filtering
void filter() {
    emg1 = emg1_in.read();
    emg1highfilter = filterhigh.step(emg1);
    emg1notchfilter = filternotch.step(emg1highfilter);
    emg1abs = fabs(emg1notchfilter);
    emg1lowfilter = filterlow.step(emg1abs);
    emgpeak = filterpeak.step(emg1lowfilter);

    emg2 = emg2_in.read();
    emg2highfilter = filterhigh.step(emg2);
    emg2notchfilter = filternotch.step(emg2highfilter);
    emg2abs = fabs(emg2notchfilter);
    emg2lowfilter = filterlow.step(emg2abs);

    /* 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, emg1_in.read() );
    scope.set(1, emg1lowfilter );
    scope.set(2, emgpeak );
    /*  Finally, send all channels to the PC at once */
    scope.send();
    /* To indicate that the function is working, the LED is toggled */
    green = !green;
}

int main()
{   

    sample_timer.attach(&filter, 0.001);

    while(1) {}
}