Emg filter function script for a uni project. Made by Teun van der Molen

Dependencies:   HIDScope MODSERIAL mbed

Committer:
teunman
Date:
Fri Sep 18 12:36:54 2015 +0000
Revision:
0:674026fdd982
Child:
1:75f61e111ed0
Working sin wave from analog output to analog input using cable;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
teunman 0:674026fdd982 1 #include "mbed.h"
teunman 0:674026fdd982 2 #include "HIDScope.h"
teunman 0:674026fdd982 3 #include "math.h"
teunman 0:674026fdd982 4 // Define the HIDScope and Ticker object
teunman 0:674026fdd982 5 HIDScope scope(1);
teunman 0:674026fdd982 6 Ticker scopeTimer;
teunman 0:674026fdd982 7
teunman 0:674026fdd982 8 // Read the analog input
teunman 0:674026fdd982 9 AnalogIn an_in(A0);
teunman 0:674026fdd982 10 AnalogOut an_out(DAC0_OUT);
teunman 0:674026fdd982 11 // The data read and send function
teunman 0:674026fdd982 12 void scopeSend()
teunman 0:674026fdd982 13 {
teunman 0:674026fdd982 14 scope.set(0,an_in.read());
teunman 0:674026fdd982 15 scope.send();
teunman 0:674026fdd982 16 }
teunman 0:674026fdd982 17
teunman 0:674026fdd982 18 int main()
teunman 0:674026fdd982 19 {
teunman 0:674026fdd982 20 // Attach the data read and send function at 100 Hz
teunman 0:674026fdd982 21 scopeTimer.attach_us(&scopeSend, 1e4);
teunman 0:674026fdd982 22 float i = 1;
teunman 0:674026fdd982 23 while(1) {
teunman 0:674026fdd982 24 // sinewave output
teunman 0:674026fdd982 25 // for (int i = 1; i < 360; i++) {
teunman 0:674026fdd982 26
teunman 0:674026fdd982 27 float func = 0.5 + 0.5*sin(i);
teunman 0:674026fdd982 28 i = i+0.01;
teunman 0:674026fdd982 29 an_out = func;
teunman 0:674026fdd982 30 wait(0.001);
teunman 0:674026fdd982 31 // }
teunman 0:674026fdd982 32 }
teunman 0:674026fdd982 33 }