atoombom
Dependencies: Encoder HIDScope mbed
Fork of EMG by
Diff: main.cpp
- Revision:
- 18:4ebf5e640f0c
- Parent:
- 16:9f7797ffd0fb
- Child:
- 19:6eefdb204444
--- a/main.cpp Tue Sep 22 07:00:54 2015 +0000 +++ b/main.cpp Mon Sep 28 10:11:01 2015 +0000 @@ -1,16 +1,21 @@ #include "mbed.h" #include "HIDScope.h" +#include "LowPassFilter.h" //Define objects AnalogIn emg(A0); //Analog input Ticker sample_timer; +Timer timer; HIDScope scope(1); +InterruptIn button(PTA4); +DigitalOut led(LED4); /** Sample function * this function samples the emg and sends it to HIDScope **/ void sample() { + if(timer.read()<5){ /* First, sample the EMG using the 'read' method of the 'AnalogIn' variable named 'emg' */ double emg_value = emg.read(); /* Second, set the sampled emg value in channel zero (the first channel) in the 'HIDScope' variable named 'scope' */ @@ -18,13 +23,24 @@ /* Repeat the step above if required for more channels (channel 0 up to 5 = 6 channels) */ /* Finally, send all channels to the PC at once */ scope.send(); + } + if(emg.read()>=0.7){ + led.write(0); + led.write(1); + } } +void time(){ + timer.start(); + } + int main() { + led=!led; /**Attach the 'sample' function to the timer 'sample_timer'. * this ensures that 'sample' is executed every... 0.002 seconds */ + button.fall(&time); sample_timer.attach(&sample, 0.002); /*empty loop, sample() is executed periodically*/