voor DION

Dependencies:   HIDScope mbed

Fork of EMG by Tom Tom

Committer:
tomlankhorst
Date:
Mon Sep 21 13:48:00 2015 +0000
Revision:
14:f83354387756
Parent:
13:18d4cef1fdb4
Child:
15:0da764eea774
EMG Sampler

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vsluiter 0:32bb76391d89 1 #include "mbed.h"
vsluiter 6:80c13d99aa55 2 #include "MODSERIAL.h"
vsluiter 11:ce72ec658a95 3 #include "HIDScope.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;
tomlankhorst 14:f83354387756 8 HIDScope scope(1);
vsluiter 2:e314bb3b2d99 9
tomlankhorst 14:f83354387756 10 /** Sample function
tomlankhorst 14:f83354387756 11 * this function samples the emg and sends it to HIDScope
tomlankhorst 14:f83354387756 12 **/
tomlankhorst 14:f83354387756 13 void sample()
vsluiter 2:e314bb3b2d99 14 {
tomlankhorst 14:f83354387756 15 /* First, sample the EMG using the 'read' method of the 'AnalogIn' variable named 'emg' */
tomlankhorst 14:f83354387756 16 double emg_value = emg.read();
tomlankhorst 14:f83354387756 17 /* Second, set the sampled emg value in channel zero (the first channel) in the 'HIDScope' variable named 'scope' */
vsluiter 11:ce72ec658a95 18 scope.set(0,emg_value);
tomlankhorst 14:f83354387756 19 /* Repeat the step above if required for more channels (channel 0 up to 5 = 6 channels)
tomlankhorst 14:f83354387756 20 /* Finally, send all channels to the PC at once */
vsluiter 11:ce72ec658a95 21 scope.send();
vsluiter 2:e314bb3b2d99 22 }
vsluiter 0:32bb76391d89 23
vsluiter 0:32bb76391d89 24 int main()
vsluiter 0:32bb76391d89 25 {
tomlankhorst 14:f83354387756 26 /**Attach the 'sample' function to the timer 'sample_timer'.
tomlankhorst 14:f83354387756 27 * this ensures that 'sample' is executed every... 0.002 seconds
vsluiter 4:8b298dfada81 28 */
tomlankhorst 14:f83354387756 29 sample_timer.attach(&sample, 0.002);
tomlankhorst 14:f83354387756 30
tomlankhorst 14:f83354387756 31 /*empty loop, sample() is executed periodically*/
tomlankhorst 14:f83354387756 32 while(1){}
vsluiter 0:32bb76391d89 33 }