8 option EMG
Dependencies: HIDScope MODSERIAL QEI biquadFilter mbed
main.cpp@16:9f7797ffd0fb, 2015-09-21 (annotated)
- Committer:
- tomlankhorst
- Date:
- Mon Sep 21 17:49:26 2015 +0000
- Revision:
- 16:9f7797ffd0fb
- Parent:
- 15:0da764eea774
- Child:
- 18:21d8e7a81cf5
Simplification
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vsluiter | 0:32bb76391d89 | 1 | #include "mbed.h" |
vsluiter | 11:ce72ec658a95 | 2 | #include "HIDScope.h" |
vsluiter | 0:32bb76391d89 | 3 | |
vsluiter | 4:8b298dfada81 | 4 | //Define objects |
tomlankhorst | 14:f83354387756 | 5 | AnalogIn emg(A0); //Analog input |
tomlankhorst | 14:f83354387756 | 6 | Ticker sample_timer; |
tomlankhorst | 14:f83354387756 | 7 | HIDScope scope(1); |
vsluiter | 2:e314bb3b2d99 | 8 | |
tomlankhorst | 14:f83354387756 | 9 | /** Sample function |
tomlankhorst | 14:f83354387756 | 10 | * this function samples the emg and sends it to HIDScope |
tomlankhorst | 14:f83354387756 | 11 | **/ |
tomlankhorst | 14:f83354387756 | 12 | void sample() |
vsluiter | 2:e314bb3b2d99 | 13 | { |
tomlankhorst | 14:f83354387756 | 14 | /* First, sample the EMG using the 'read' method of the 'AnalogIn' variable named 'emg' */ |
tomlankhorst | 14:f83354387756 | 15 | double emg_value = emg.read(); |
tomlankhorst | 14:f83354387756 | 16 | /* Second, set the sampled emg value in channel zero (the first channel) in the 'HIDScope' variable named 'scope' */ |
vsluiter | 11:ce72ec658a95 | 17 | scope.set(0,emg_value); |
tomlankhorst | 16:9f7797ffd0fb | 18 | /* Repeat the step above if required for more channels (channel 0 up to 5 = 6 channels) */ |
tomlankhorst | 14:f83354387756 | 19 | /* Finally, send all channels to the PC at once */ |
vsluiter | 11:ce72ec658a95 | 20 | scope.send(); |
vsluiter | 2:e314bb3b2d99 | 21 | } |
vsluiter | 0:32bb76391d89 | 22 | |
vsluiter | 0:32bb76391d89 | 23 | int main() |
vsluiter | 0:32bb76391d89 | 24 | { |
tomlankhorst | 14:f83354387756 | 25 | /**Attach the 'sample' function to the timer 'sample_timer'. |
tomlankhorst | 14:f83354387756 | 26 | * this ensures that 'sample' is executed every... 0.002 seconds |
vsluiter | 4:8b298dfada81 | 27 | */ |
tomlankhorst | 14:f83354387756 | 28 | sample_timer.attach(&sample, 0.002); |
tomlankhorst | 15:0da764eea774 | 29 | |
tomlankhorst | 14:f83354387756 | 30 | /*empty loop, sample() is executed periodically*/ |
tomlankhorst | 15:0da764eea774 | 31 | while(1) {} |
vsluiter | 0:32bb76391d89 | 32 | } |