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:
21:136a1ab8163c
Parent:
20:97059009a491
Child:
22:68ab712b62b2

File content as of revision 21:136a1ab8163c:

#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( 4 );
DigitalOut  red(LED_RED);
DigitalOut  blue(LED_BLUE);
DigitalOut  green(LED_GREEN);
MODSERIAL   pc(USBTX, USBRX);


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

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(8.883e-01,1.7671,8.835e-01,1.7227,8.114e-01)

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

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

void sample()
{
    /* 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.read() );
    scope.set(2, emg2_in.read() );
    scope.set() emg2lowfilter.read() );
    /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels) 
    *  Ensure that enough channels are available (HIDScope scope( 2 ))
    *  Finally, send all channels to the PC at once */
    scope.send();
    /* To indicate that the function is working, the LED is toggled */
    led = !led;
}

int main()
{   
    /**Attach the 'sample' function to the timer 'sample_timer'.
    * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz
    */
    sample_timer.attach(&sample, 0.001);

    /*empty loop, sample() is executed periodically*/
    while(1) {}
}