
Low end EMG measuring
main.cpp@0:498fc20f5c30, 2018-09-27 (annotated)
- Committer:
- CasperK
- Date:
- Thu Sep 27 13:07:35 2018 +0000
- Revision:
- 0:498fc20f5c30
Low end EMG measuring of 2 muscles
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CasperK | 0:498fc20f5c30 | 1 | #include "mbed.h" |
CasperK | 0:498fc20f5c30 | 2 | #include "HIDScope.h" |
CasperK | 0:498fc20f5c30 | 3 | |
CasperK | 0:498fc20f5c30 | 4 | //Define objects |
CasperK | 0:498fc20f5c30 | 5 | AnalogIn emg0( A0 ); |
CasperK | 0:498fc20f5c30 | 6 | AnalogIn emg1( A1 ); |
CasperK | 0:498fc20f5c30 | 7 | |
CasperK | 0:498fc20f5c30 | 8 | Ticker sample_timer; |
CasperK | 0:498fc20f5c30 | 9 | HIDScope scope( 4 ); |
CasperK | 0:498fc20f5c30 | 10 | DigitalOut led(LED1); |
CasperK | 0:498fc20f5c30 | 11 | |
CasperK | 0:498fc20f5c30 | 12 | /** Sample function |
CasperK | 0:498fc20f5c30 | 13 | * this function samples the emg and sends it to HIDScope |
CasperK | 0:498fc20f5c30 | 14 | **/ |
CasperK | 0:498fc20f5c30 | 15 | void sample() |
CasperK | 0:498fc20f5c30 | 16 | { |
CasperK | 0:498fc20f5c30 | 17 | /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */ |
CasperK | 0:498fc20f5c30 | 18 | scope.set(0, emg0.read() ); |
CasperK | 0:498fc20f5c30 | 19 | scope.set(1, emg1.read() ); |
CasperK | 0:498fc20f5c30 | 20 | |
CasperK | 0:498fc20f5c30 | 21 | scope.send(); |
CasperK | 0:498fc20f5c30 | 22 | /* To indicate that the function is working, the LED is toggled */ |
CasperK | 0:498fc20f5c30 | 23 | led = !led; |
CasperK | 0:498fc20f5c30 | 24 | } |
CasperK | 0:498fc20f5c30 | 25 | |
CasperK | 0:498fc20f5c30 | 26 | int main() |
CasperK | 0:498fc20f5c30 | 27 | { |
CasperK | 0:498fc20f5c30 | 28 | /**Attach the 'sample' function to the timer 'sample_timer'. |
CasperK | 0:498fc20f5c30 | 29 | * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz |
CasperK | 0:498fc20f5c30 | 30 | */ |
CasperK | 0:498fc20f5c30 | 31 | sample_timer.attach(&sample, 0.002); |
CasperK | 0:498fc20f5c30 | 32 | |
CasperK | 0:498fc20f5c30 | 33 | /*empty loop, sample() is executed periodically*/ |
CasperK | 0:498fc20f5c30 | 34 | while(1) {} |
CasperK | 0:498fc20f5c30 | 35 | } |