Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HIDScope mbed MODSERIAL
main.cpp
- Committer:
- Bartvaart
- Date:
- 2015-10-14
- Revision:
- 21:8fe8419de3e9
- Parent:
- 20:11e1244ad2ad
- Child:
- 22:c1811e60bfce
File content as of revision 21:8fe8419de3e9:
#include "mbed.h"
#include "HIDScope.h"
#include "Filterdesigns.h"
#include "Kalibratie.h"
#include "MODSERIAL.h" //bugfix
#include "Mode.h"
AnalogIn emg(A0); //Analog input van emg kabels
HIDScope scope(3); //3 scopes
Ticker EMGticker;
MODSERIAL pc(USBTX, USBRX); //bugfix
DigitalOut LedBlue(LED3);
DigitalIn button(PTA4);
//Sample frequentie
double Fs = 500; //Hz
double t = 1/ Fs; // voor EMGticker
bool readymax = 0;
bool readymin = 0;
double ymin;
double ymax;
double thresholdlow;
double thresholdmid;
double thresholdhigh;
void EMGkalibratie()
{
LedBlue = 1;
Init();
ymin = KalibratieMin(readymin);
wait(1);
ymax = KalibratieMax(readymax);
// bepalen van thresholds voor aan/uit
thresholdlow = 10 * ymin; // standaardwaarde
thresholdmid = 0.5 * ymax; // afhankelijk van max output gebruiker
thresholdhigh = 0.8 * ymax;
}
void EMGfilter()
{
//uitlezen emg signaal
double u = emg.read();
double y = Filterdesigns(u);
//pc.printf("%f \n",y); //bugfix
// Plotten in HIDscope
int mode = Mode(y, ymax, thresholdlow, thresholdmid, thresholdhigh); //bepaald welk signaal de motor krijgt (aan, uit, middel)
scope.set(0,u); //ongefilterde waarde naar scope 1
scope.set(1,y); //gefilterde waarde naar scope 2
scope.set(2,mode);
scope.send(); //stuur de waardes naar HIDscope
}
int main()
{
while(1) {
if(readymax == 0 || readymin == 0) {
EMGkalibratie();
pc.printf("ymax = %f en ymin = %f \n",ymax, ymin); //bugfix
}
EMGticker.attach(&EMGfilter, t); //500H
while(readymax == 1 && readymin == 1) {
if(button == 0) {
readymax = 0;
readymin = 0;
}
}
}
}