emg including calibration, (pin values still has to be checked and determined what we want as the gain. this calibration is don over the all the muscles at once

Dependencies:   HIDScope mbed

Fork of Low_end_EMG_measuring by Casper Kroon

Committer:
michelvos12
Date:
Thu Oct 18 09:37:39 2018 +0000
Revision:
1:1a38cc6622f6
Parent:
0:498fc20f5c30
emg including calibration

Who changed what in which revision?

UserRevisionLine numberNew 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
michelvos12 1:1a38cc6622f6 5 AnalogIn emg0( A0 ); //emg sensor A0
michelvos12 1:1a38cc6622f6 6 AnalogIn emg1( A1 ); //emg sensor A1
michelvos12 1:1a38cc6622f6 7 AnalogIn emg2( A2 ); //emg sensor A3
michelvos12 1:1a38cc6622f6 8 DigitalIn button_emg(D4); //button for emg calibration (pin must be ckecked if empty
CasperK 0:498fc20f5c30 9
CasperK 0:498fc20f5c30 10 Ticker sample_timer;
michelvos12 1:1a38cc6622f6 11 HIDScope scope( 6 ); //6 channels in hidscope
CasperK 0:498fc20f5c30 12 DigitalOut led(LED1);
CasperK 0:498fc20f5c30 13
CasperK 0:498fc20f5c30 14 /** Sample function
michelvos12 1:1a38cc6622f6 15 * this function_Samples the emg_and_Sends it to HIDScope_
CasperK 0:498fc20f5c30 16 **/
CasperK 0:498fc20f5c30 17 void sample()
CasperK 0:498fc20f5c30 18 {
CasperK 0:498fc20f5c30 19 /* 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 20 scope.set(0, emg0.read() );
CasperK 0:498fc20f5c30 21 scope.set(1, emg1.read() );
michelvos12 1:1a38cc6622f6 22 scope.set(2, emg2.read() );
CasperK 0:498fc20f5c30 23
CasperK 0:498fc20f5c30 24 scope.send();
CasperK 0:498fc20f5c30 25 /* To indicate that the function is working, the LED is toggled */
CasperK 0:498fc20f5c30 26 led = !led;
CasperK 0:498fc20f5c30 27 }
CasperK 0:498fc20f5c30 28
CasperK 0:498fc20f5c30 29 int main()
CasperK 0:498fc20f5c30 30 {
CasperK 0:498fc20f5c30 31 /**Attach the 'sample' function to the timer 'sample_timer'.
CasperK 0:498fc20f5c30 32 * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz
CasperK 0:498fc20f5c30 33 */
michelvos12 1:1a38cc6622f6 34 //______emg calibration______//
michelvos12 1:1a38cc6622f6 35 while (button_emg == false) {
michelvos12 1:1a38cc6622f6 36 if (&sample >= 0,05) {
michelvos12 1:1a38cc6622f6 37 &sample = &sample*2;
michelvos12 1:1a38cc6622f6 38 }
michelvos12 1:1a38cc6622f6 39 else if (&sample >= 0,2) {
michelvos12 1:1a38cc6622f6 40 &sample = &sample;
michelvos12 1:1a38cc6622f6 41 }
michelvos12 1:1a38cc6622f6 42 else ($sample >= 0,5) {
michelvos12 1:1a38cc6622f6 43 &sample = &sample/2;
michelvos12 1:1a38cc6622f6 44 }
michelvos12 1:1a38cc6622f6 45 }
michelvos12 1:1a38cc6622f6 46 while (button_emg == true) {
CasperK 0:498fc20f5c30 47 sample_timer.attach(&sample, 0.002);
michelvos12 1:1a38cc6622f6 48 }
CasperK 0:498fc20f5c30 49 /*empty loop, sample() is executed periodically*/
CasperK 0:498fc20f5c30 50 while(1) {}
CasperK 0:498fc20f5c30 51 }