Roy van Zijl
/
EMG
voor DION
Fork of EMG by
main.cpp@21:82bfc2fe215e, 2017-11-06 (annotated)
- Committer:
- RoyvZ
- Date:
- Mon Nov 06 14:46:01 2017 +0000
- Revision:
- 21:82bfc2fe215e
- Parent:
- 20:97059009a491
voor DION;
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 | 19:2bf824669684 | 5 | AnalogIn emg0( A0 ); |
tomlankhorst | 19:2bf824669684 | 6 | AnalogIn emg1( A1 ); |
tomlankhorst | 19:2bf824669684 | 7 | |
tomlankhorst | 14:f83354387756 | 8 | Ticker sample_timer; |
tomlankhorst | 19:2bf824669684 | 9 | HIDScope scope( 2 ); |
tomlankhorst | 18:21d8e7a81cf5 | 10 | DigitalOut led(LED1); |
RoyvZ | 21:82bfc2fe215e | 11 | DigitalOut led2(LED_GREEN); |
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 | { |
tomlankhorst | 19:2bf824669684 | 18 | /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */ |
tomlankhorst | 19:2bf824669684 | 19 | scope.set(0, emg0.read() ); |
tomlankhorst | 19:2bf824669684 | 20 | scope.set(1, emg1.read() ); |
tomlankhorst | 19:2bf824669684 | 21 | /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels) |
tomlankhorst | 19:2bf824669684 | 22 | * Ensure that enough channels are available (HIDScope scope( 2 )) |
tomlankhorst | 20:97059009a491 | 23 | * Finally, send all channels to the PC at once */ |
vsluiter | 11:ce72ec658a95 | 24 | scope.send(); |
tomlankhorst | 18:21d8e7a81cf5 | 25 | /* To indicate that the function is working, the LED is toggled */ |
tomlankhorst | 18:21d8e7a81cf5 | 26 | led = !led; |
vsluiter | 2:e314bb3b2d99 | 27 | } |
vsluiter | 0:32bb76391d89 | 28 | |
vsluiter | 0:32bb76391d89 | 29 | int main() |
tomlankhorst | 19:2bf824669684 | 30 | { |
tomlankhorst | 14:f83354387756 | 31 | /**Attach the 'sample' function to the timer 'sample_timer'. |
tomlankhorst | 19:2bf824669684 | 32 | * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz |
vsluiter | 4:8b298dfada81 | 33 | */ |
tomlankhorst | 19:2bf824669684 | 34 | sample_timer.attach(&sample, 0.002); |
tomlankhorst | 15:0da764eea774 | 35 | |
tomlankhorst | 14:f83354387756 | 36 | /*empty loop, sample() is executed periodically*/ |
RoyvZ | 21:82bfc2fe215e | 37 | while(true) { |
RoyvZ | 21:82bfc2fe215e | 38 | } |
vsluiter | 0:32bb76391d89 | 39 | } |