Hidscope + EMG

Dependencies:   HIDScope biquadFilter mbed

main.cpp

Committer:
Iriskolenbrander9
Date:
2018-10-22
Revision:
3:76d32bcfde05
Parent:
2:b2d117949de7
Child:
4:034f2bd0c75d

File content as of revision 3:76d32bcfde05:

#include "mbed.h"
#include "HIDScope.h"
#include "BiQuad.h"
 
// Define the HIDScope and Ticker object
HIDScope    scope(3);
Ticker      scopeTimer;

BiQuadChain bqc;
BiQuad      bq1(0.2928920553392428, 0.5857841106784856, 0.2928920553392428, -1.3007020142696517e-16,0.17156822135697122);
BiQuad      bq2(0.9599250424722232, -1.9198500849444464, 0.9599250424722232, -1.9179540214230233, 0.9217461484658696); 
BiQuad      bq3(0.9340059945350248, -1.84501366169642, 0.9340059945350248, -1.84501366169642, 0.8680119890700493);
BiQuad      bq4(0.7902104553475195, -1.278587375017818, 0.7902104553475195, -1.278587375017818, 0.5804209106950391);

// Read the analog input
AnalogIn    emg1(A0);
AnalogIn    emg2(A1);

double emgSample() 
{
    double emgFiltered = bqc.step(emg1.read());
    return emgFiltered;
}

// The data read and send function
void scopeSend()
{
    scope.set(0,emg1.read());
    scope.set(1,emg2.read());
    scope.set(2,emgSample());
    scope.send();
}
 
int main()
{
    // Attach the data read and send function at 100 Hz
    bqc.add( &bq1 ).add( &bq2 ).add(&bq3).add(&bq4);
    scopeTimer.attach_us(&scopeSend, 2e3);   
    
    while(1) { }
}