atoombom

Dependencies:   Encoder HIDScope mbed

Fork of EMG by Tom Tom

Committer:
Bartvaart
Date:
Mon Sep 28 10:11:01 2015 +0000
Revision:
18:4ebf5e640f0c
Parent:
16:9f7797ffd0fb
Child:
19:6eefdb204444
Eerste poging kopie uit sheets Biquad filter

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vsluiter 0:32bb76391d89 1 #include "mbed.h"
vsluiter 11:ce72ec658a95 2 #include "HIDScope.h"
Bartvaart 18:4ebf5e640f0c 3 #include "LowPassFilter.h"
vsluiter 0:32bb76391d89 4
vsluiter 4:8b298dfada81 5 //Define objects
tomlankhorst 14:f83354387756 6 AnalogIn emg(A0); //Analog input
tomlankhorst 14:f83354387756 7 Ticker sample_timer;
Bartvaart 18:4ebf5e640f0c 8 Timer timer;
tomlankhorst 14:f83354387756 9 HIDScope scope(1);
Bartvaart 18:4ebf5e640f0c 10 InterruptIn button(PTA4);
Bartvaart 18:4ebf5e640f0c 11 DigitalOut led(LED4);
vsluiter 2:e314bb3b2d99 12
tomlankhorst 14:f83354387756 13 /** Sample function
tomlankhorst 14:f83354387756 14 * this function samples the emg and sends it to HIDScope
tomlankhorst 14:f83354387756 15 **/
tomlankhorst 14:f83354387756 16 void sample()
vsluiter 2:e314bb3b2d99 17 {
Bartvaart 18:4ebf5e640f0c 18 if(timer.read()<5){
tomlankhorst 14:f83354387756 19 /* First, sample the EMG using the 'read' method of the 'AnalogIn' variable named 'emg' */
tomlankhorst 14:f83354387756 20 double emg_value = emg.read();
tomlankhorst 14:f83354387756 21 /* Second, set the sampled emg value in channel zero (the first channel) in the 'HIDScope' variable named 'scope' */
vsluiter 11:ce72ec658a95 22 scope.set(0,emg_value);
tomlankhorst 16:9f7797ffd0fb 23 /* Repeat the step above if required for more channels (channel 0 up to 5 = 6 channels) */
tomlankhorst 14:f83354387756 24 /* Finally, send all channels to the PC at once */
vsluiter 11:ce72ec658a95 25 scope.send();
Bartvaart 18:4ebf5e640f0c 26 }
Bartvaart 18:4ebf5e640f0c 27 if(emg.read()>=0.7){
Bartvaart 18:4ebf5e640f0c 28 led.write(0);
Bartvaart 18:4ebf5e640f0c 29 led.write(1);
Bartvaart 18:4ebf5e640f0c 30 }
vsluiter 2:e314bb3b2d99 31 }
vsluiter 0:32bb76391d89 32
Bartvaart 18:4ebf5e640f0c 33 void time(){
Bartvaart 18:4ebf5e640f0c 34 timer.start();
Bartvaart 18:4ebf5e640f0c 35 }
Bartvaart 18:4ebf5e640f0c 36
vsluiter 0:32bb76391d89 37 int main()
vsluiter 0:32bb76391d89 38 {
Bartvaart 18:4ebf5e640f0c 39 led=!led;
tomlankhorst 14:f83354387756 40 /**Attach the 'sample' function to the timer 'sample_timer'.
tomlankhorst 14:f83354387756 41 * this ensures that 'sample' is executed every... 0.002 seconds
vsluiter 4:8b298dfada81 42 */
Bartvaart 18:4ebf5e640f0c 43 button.fall(&time);
tomlankhorst 14:f83354387756 44 sample_timer.attach(&sample, 0.002);
tomlankhorst 15:0da764eea774 45
tomlankhorst 14:f83354387756 46 /*empty loop, sample() is executed periodically*/
tomlankhorst 15:0da764eea774 47 while(1) {}
vsluiter 0:32bb76391d89 48 }