test
Dependencies: HIDScope MODSERIAL mbed-dsp mbed
Fork of emg_filter2 by
EMGfilter.cpp@60:7b5ca1a4d7c3, 2014-10-20 (annotated)
- Committer:
- s1340735
- Date:
- Mon Oct 20 17:59:08 2014 +0000
- Revision:
- 60:7b5ca1a4d7c3
- Parent:
- 59:fa8d6909d8ac
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
s1340735 | 22:dc630dbb1dcd | 1 | #include "mbed.h" |
s1340735 | 22:dc630dbb1dcd | 2 | #include "HIDScope.h" |
s1340735 | 23:1c51af8386c9 | 3 | #include "MODSERIAL.h" |
s1340735 | 22:dc630dbb1dcd | 4 | #include "arm_math.h" |
s1340735 | 22:dc630dbb1dcd | 5 | |
s1340735 | 22:dc630dbb1dcd | 6 | //Define objects |
s1340735 | 22:dc630dbb1dcd | 7 | AnalogIn emgB(PTB0); //Analog input bicep |
s1340735 | 22:dc630dbb1dcd | 8 | AnalogIn emgT(PTB1); //Analog input tricep |
s1340735 | 22:dc630dbb1dcd | 9 | |
s1340735 | 23:1c51af8386c9 | 10 | float filtered_emgB; |
s1340735 | 27:24e73fd36859 | 11 | float filtered_emgT; |
Tanja2211 | 57:5136d9823508 | 12 | float MeanT2, MeanB1, MeanB2, MeanB3; |
Tanja2211 | 56:57a5fcfdce72 | 13 | float filtered_emgT10_C, filtered_emgT11_C, filtered_emgT12_C, filtered_emgT13_C, filtered_emgT14_C, filtered_emgT15_C, filtered_emgT16_C, filtered_emgT17_C, filtered_emgT18_C, filtered_emgT19_C, filtered_emgT110_C, filtered_emgT111_C, filtered_emgT112_C, filtered_emgT113_C, filtered_emgT114_C, filtered_emgT115_C, filtered_emgT116_C, filtered_emgT117_C, filtered_emgT118_C, filtered_emgT119_C; |
Tanja2211 | 51:809e38348c91 | 14 | float B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, MOVAVG_B; |
Tanja2211 | 51:809e38348c91 | 15 | float T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, MOVAVG_T; |
Tanja2211 | 54:f3a9fa5f2b0e | 16 | float drempelwaardeB1, drempelwaardeB2, drempelwaardeB3, drempelwaardeT1, drempelwaardeT2; |
s1340735 | 23:1c51af8386c9 | 17 | |
s1340735 | 23:1c51af8386c9 | 18 | MODSERIAL pc(USBTX,USBRX); |
s1340735 | 23:1c51af8386c9 | 19 | |
s1340735 | 60:7b5ca1a4d7c3 | 20 | HIDScope scope(2);//uitgang scherm |
s1340735 | 22:dc630dbb1dcd | 21 | |
s1340735 | 22:dc630dbb1dcd | 22 | arm_biquad_casd_df1_inst_f32 lowpass; |
s1340735 | 22:dc630dbb1dcd | 23 | //constants for 50Hz lowpass |
s1340735 | 30:5d8e6f0fabc1 | 24 | float lowpass_const[] = {0.2928920553, 0.5857841107, 0.2928920554, -0, -0.17156822136};//{a0 a1 a2 -b1 -b2} van online calculator |
s1340735 | 22:dc630dbb1dcd | 25 | //state values |
s1340735 | 26:b93c82fb6e1d | 26 | float lowpass_states[4]; |
s1340735 | 22:dc630dbb1dcd | 27 | |
s1340735 | 22:dc630dbb1dcd | 28 | arm_biquad_casd_df1_inst_f32 highpass; |
s1340735 | 22:dc630dbb1dcd | 29 | //constants for 10Hz highpass |
s1340735 | 26:b93c82fb6e1d | 30 | float highpass_const[] = {0.8005910267, -1.6011820533, 0.8005910267, 1.5610153913, -0.6413487154};//{a0 a1 a2 -b1 -b2} |
s1340735 | 22:dc630dbb1dcd | 31 | //state values |
s1340735 | 26:b93c82fb6e1d | 32 | float highpass_states[4]; |
s1340735 | 22:dc630dbb1dcd | 33 | |
s1340735 | 22:dc630dbb1dcd | 34 | |
s1340735 | 22:dc630dbb1dcd | 35 | /** Looper function |
s1340735 | 22:dc630dbb1dcd | 36 | * functions used for Ticker and Timeout should be of type void <name>(void) |
s1340735 | 22:dc630dbb1dcd | 37 | * i.e. no input arguments, no output arguments. |
s1340735 | 22:dc630dbb1dcd | 38 | * if you want to change a variable that you use in other places (for example in main) |
s1340735 | 22:dc630dbb1dcd | 39 | * you will have to make that variable global in order to be able to reach it both from |
s1340735 | 22:dc630dbb1dcd | 40 | * the function called at interrupt time, and in the main function. |
s1340735 | 22:dc630dbb1dcd | 41 | * To make a variable global, define it under the includes. |
s1340735 | 22:dc630dbb1dcd | 42 | * variables that are changed in the interrupt routine (written to) should be made |
s1340735 | 22:dc630dbb1dcd | 43 | * 'volatile' to let the compiler know that those values may change outside the current context. |
s1340735 | 22:dc630dbb1dcd | 44 | * i.e.: "volatile uint16_t emg_value;" instead of "uint16_t emg_value" |
s1340735 | 22:dc630dbb1dcd | 45 | * in the example below, the variable is not re-used in the main function, and is thus declared |
s1340735 | 22:dc630dbb1dcd | 46 | * local in the looper function only. |
s1340735 | 22:dc630dbb1dcd | 47 | **/ |
s1340735 | 22:dc630dbb1dcd | 48 | |
Tanja2211 | 55:f215d954533c | 49 | // Calibratie |
Tanja2211 | 55:f215d954533c | 50 | |
s1340735 | 60:7b5ca1a4d7c3 | 51 | void Calibratie() |
Tanja2211 | 56:57a5fcfdce72 | 52 | { |
s1340735 | 60:7b5ca1a4d7c3 | 53 | pc.printf("Calibratie drempelwaarde Triceps stand 1\n"); |
s1340735 | 60:7b5ca1a4d7c3 | 54 | wait(0.5); |
s1340735 | 60:7b5ca1a4d7c3 | 55 | { |
s1340735 | 60:7b5ca1a4d7c3 | 56 | int i; |
s1340735 | 60:7b5ca1a4d7c3 | 57 | int j=19; |
Tanja2211 | 58:b5bb78380767 | 58 | |
s1340735 | 60:7b5ca1a4d7c3 | 59 | for (i=0, i<=j; i++) { |
s1340735 | 60:7b5ca1a4d7c3 | 60 | /*variable to store value in*/ |
s1340735 | 60:7b5ca1a4d7c3 | 61 | uint16_t emg_valueT1i_C; |
Tanja2211 | 55:f215d954533c | 62 | |
s1340735 | 60:7b5ca1a4d7c3 | 63 | float emg_value_f32T1i_C; |
s1340735 | 60:7b5ca1a4d7c3 | 64 | /*put raw emg value both in red and in emg_value*/ |
s1340735 | 60:7b5ca1a4d7c3 | 65 | emg_valueT1i_C = emgT1i_C.read_u16(); // read direct ADC result, converted to 16 bit integer (0..2^16 = 0..65536 = 0..3.3V) |
s1340735 | 60:7b5ca1a4d7c3 | 66 | emg_value_f32T1i_C = emgT1i_C.read(); |
s1340735 | 60:7b5ca1a4d7c3 | 67 | |
s1340735 | 60:7b5ca1a4d7c3 | 68 | //process emg |
s1340735 | 60:7b5ca1a4d7c3 | 69 | arm_biquad_cascade_df1_f32(&highpass, &emg_value_f32T1i_C, &filtered_emgT1i_C, 1 ); |
s1340735 | 60:7b5ca1a4d7c3 | 70 | filtered_emgT1i_C = fabs(filtered_emgT1i_C); |
s1340735 | 60:7b5ca1a4d7c3 | 71 | arm_biquad_cascade_df1_f32(&lowpass, &filtered_emgT1i_C, &filtered_emgT1i_C, 1 ); |
s1340735 | 60:7b5ca1a4d7c3 | 72 | } |
Tanja2211 | 58:b5bb78380767 | 73 | } |
Tanja2211 | 58:b5bb78380767 | 74 | } |
Tanja2211 | 55:f215d954533c | 75 | |
s1340735 | 60:7b5ca1a4d7c3 | 76 | // Mean Triceps stand 1 |
s1340735 | 60:7b5ca1a4d7c3 | 77 | void MeanTriceps() |
s1340735 | 60:7b5ca1a4d7c3 | 78 | { |
Tanja2211 | 58:b5bb78380767 | 79 | |
s1340735 | 60:7b5ca1a4d7c3 | 80 | float MeanT1=filtered_emgT10_C*0.05+filtered_emgT11_C*0.05+filtered_emgT12_C*0.05+filtered_emgT13_C*0.05+filtered_emgT14_C*0.05+filtered_emgT15_C*0.05+filtered_emgT16_C*0.05+filtered_emgT17_C*0.05+filtered_emgT18_C*0.05+filtered_emgT19_C*0.05+filtered_emgT110_C*0.05+filtered_emgT111_C*0.05+filtered_emgT112_C*0.05+filtered_emgT113_C*0.05+filtered_emgT114_C*0.05+filtered_emgT115_C*0.05+filtered_emgT116_C*0.05+filtered_emgT117_C*0.05+filtered_emgT118_C*0.05+filtered_emgT119_C*0.05; |
Tanja2211 | 55:f215d954533c | 81 | |
s1340735 | 60:7b5ca1a4d7c3 | 82 | } |
Tanja2211 | 55:f215d954533c | 83 | |
s1340735 | 22:dc630dbb1dcd | 84 | //BICEP EMG LEZEN |
s1340735 | 22:dc630dbb1dcd | 85 | void looperB() |
s1340735 | 22:dc630dbb1dcd | 86 | { |
s1340735 | 23:1c51af8386c9 | 87 | /*variable to store value in*/ |
s1340735 | 22:dc630dbb1dcd | 88 | uint16_t emg_valueB; |
s1340735 | 30:5d8e6f0fabc1 | 89 | |
s1340735 | 22:dc630dbb1dcd | 90 | float emg_value_f32B; |
s1340735 | 22:dc630dbb1dcd | 91 | /*put raw emg value both in red and in emg_value*/ |
s1340735 | 22:dc630dbb1dcd | 92 | emg_valueB = emgB.read_u16(); // read direct ADC result, converted to 16 bit integer (0..2^16 = 0..65536 = 0..3.3V) |
s1340735 | 22:dc630dbb1dcd | 93 | emg_value_f32B = emgB.read(); |
s1340735 | 22:dc630dbb1dcd | 94 | |
s1340735 | 22:dc630dbb1dcd | 95 | //process emg |
s1340735 | 22:dc630dbb1dcd | 96 | arm_biquad_cascade_df1_f32(&highpass, &emg_value_f32B, &filtered_emgB, 1 ); |
s1340735 | 22:dc630dbb1dcd | 97 | filtered_emgB = fabs(filtered_emgB); |
s1340735 | 22:dc630dbb1dcd | 98 | arm_biquad_cascade_df1_f32(&lowpass, &filtered_emgB, &filtered_emgB, 1 ); |
s1340735 | 23:1c51af8386c9 | 99 | |
s1340735 | 22:dc630dbb1dcd | 100 | /*send value to PC. */ |
s1340735 | 22:dc630dbb1dcd | 101 | scope.set(0,emg_valueB); //uint value |
s1340735 | 22:dc630dbb1dcd | 102 | scope.set(1,filtered_emgB); //processed float |
s1340735 | 22:dc630dbb1dcd | 103 | scope.send(); |
Tanja2211 | 45:7950fa411107 | 104 | |
Tanja2211 | 44:b47f559826ba | 105 | // Moving Average Filter Biceps |
Tanja2211 | 58:b5bb78380767 | 106 | |
Tanja2211 | 36:82fd9d862266 | 107 | { |
Tanja2211 | 32:1bc34d137942 | 108 | B0=filtered_emgB; |
Tanja2211 | 42:d49b766ffdc7 | 109 | MOVAVG_B=B0*0.1+B1*0.1+B2*0.1+B3*0.1+B4*0.1+B5*0.1+B6*0.1+B7*0.1+B8*0.1+B9*0.1; |
Tanja2211 | 32:1bc34d137942 | 110 | B9=B8; |
Tanja2211 | 32:1bc34d137942 | 111 | B8=B7; |
Tanja2211 | 32:1bc34d137942 | 112 | B7=B6; |
Tanja2211 | 32:1bc34d137942 | 113 | B6=B5; |
Tanja2211 | 32:1bc34d137942 | 114 | B5=B4; |
Tanja2211 | 32:1bc34d137942 | 115 | B4=B3; |
Tanja2211 | 32:1bc34d137942 | 116 | B3=B2; |
Tanja2211 | 32:1bc34d137942 | 117 | B2=B1; |
Tanja2211 | 32:1bc34d137942 | 118 | B1=B0; |
s1340735 | 30:5d8e6f0fabc1 | 119 | } |
Tanja2211 | 45:7950fa411107 | 120 | } |
s1340735 | 60:7b5ca1a4d7c3 | 121 | |
Tanja2211 | 44:b47f559826ba | 122 | // Triceps EMG lezen |
Tanja2211 | 45:7950fa411107 | 123 | void looperT() |
Tanja2211 | 45:7950fa411107 | 124 | { |
Tanja2211 | 45:7950fa411107 | 125 | /*variable to store value in*/ |
Tanja2211 | 45:7950fa411107 | 126 | uint16_t emg_valueT; |
Tanja2211 | 31:b6f7ba4938d4 | 127 | |
Tanja2211 | 45:7950fa411107 | 128 | float emg_value_f32T; |
Tanja2211 | 45:7950fa411107 | 129 | /*put raw emg value both in red and in emg_value*/ |
Tanja2211 | 45:7950fa411107 | 130 | emg_valueT = emgT.read_u16(); // read direct ADC result, converted to 16 bit integer (0..2^16 = 0..65536 = 0..3.3V) |
Tanja2211 | 45:7950fa411107 | 131 | emg_value_f32T = emgT.read(); |
s1340735 | 22:dc630dbb1dcd | 132 | |
Tanja2211 | 45:7950fa411107 | 133 | //process emg |
Tanja2211 | 45:7950fa411107 | 134 | arm_biquad_cascade_df1_f32(&highpass, &emg_value_f32T, &filtered_emgT, 1 ); |
Tanja2211 | 45:7950fa411107 | 135 | filtered_emgT = fabs(filtered_emgT); |
Tanja2211 | 45:7950fa411107 | 136 | arm_biquad_cascade_df1_f32(&lowpass, &filtered_emgT, &filtered_emgT, 1 ); |
s1340735 | 22:dc630dbb1dcd | 137 | |
Tanja2211 | 45:7950fa411107 | 138 | /*send value to PC. */ |
Tanja2211 | 45:7950fa411107 | 139 | scope.set(2,emg_valueT); //uint value |
Tanja2211 | 45:7950fa411107 | 140 | scope.set(3,filtered_emgT); //processed float |
Tanja2211 | 45:7950fa411107 | 141 | scope.send(); |
Tanja2211 | 38:7ed04177892b | 142 | |
Tanja2211 | 58:b5bb78380767 | 143 | // Moving Average Filter Triceps |
Tanja2211 | 58:b5bb78380767 | 144 | { |
Tanja2211 | 58:b5bb78380767 | 145 | T0=filtered_emgT; |
Tanja2211 | 58:b5bb78380767 | 146 | MOVAVG_T=T0*0.1+T1*0.1+T2*0.1+T3*0.1+T4*0.1+T5*0.1+T6*0.1+T7*0.1+T8*0.1+T9*0.1; |
Tanja2211 | 38:7ed04177892b | 147 | |
Tanja2211 | 58:b5bb78380767 | 148 | T9=T8; |
Tanja2211 | 58:b5bb78380767 | 149 | T8=T7; |
Tanja2211 | 58:b5bb78380767 | 150 | T7=T6; |
Tanja2211 | 58:b5bb78380767 | 151 | T6=T5; |
Tanja2211 | 58:b5bb78380767 | 152 | T5=T4; |
Tanja2211 | 58:b5bb78380767 | 153 | T4=T3; |
Tanja2211 | 58:b5bb78380767 | 154 | T3=T2; |
Tanja2211 | 58:b5bb78380767 | 155 | T2=T1; |
Tanja2211 | 58:b5bb78380767 | 156 | T1=T0; |
Tanja2211 | 58:b5bb78380767 | 157 | } |
Tanja2211 | 50:650e8e45b870 | 158 | } |
Tanja2211 | 49:b103e9ed5ef2 | 159 | |
Tanja2211 | 45:7950fa411107 | 160 | int main() |
Tanja2211 | 45:7950fa411107 | 161 | { |
s1340735 | 60:7b5ca1a4d7c3 | 162 | Ticker log_timer,; //bicep logtimer |
Tanja2211 | 45:7950fa411107 | 163 | //set up filters. Use external array for constants |
Tanja2211 | 45:7950fa411107 | 164 | arm_biquad_cascade_df1_init_f32(&lowpass,1 , lowpass_const, lowpass_states); |
Tanja2211 | 45:7950fa411107 | 165 | arm_biquad_cascade_df1_init_f32(&highpass,1 ,highpass_const, highpass_states); |
s1340735 | 22:dc630dbb1dcd | 166 | |
Tanja2211 | 45:7950fa411107 | 167 | /**Here you attach the 'void looper(void)' function to the Ticker object |
Tanja2211 | 45:7950fa411107 | 168 | * The looper() function will be called every 0.01 seconds. |
Tanja2211 | 45:7950fa411107 | 169 | * Please mind that the parentheses after looper are omitted when using attach. |
Tanja2211 | 45:7950fa411107 | 170 | */ |
Tanja2211 | 45:7950fa411107 | 171 | log_timer.attach(looperB, 0.005);//?? |
s1340735 | 60:7b5ca1a4d7c3 | 172 | while(1) { //Loop |
s1340735 | 60:7b5ca1a4d7c3 | 173 | /*Empty!*/ |
s1340735 | 60:7b5ca1a4d7c3 | 174 | /*Everything is handled by the interrupt routine now!*/ |
s1340735 | 60:7b5ca1a4d7c3 | 175 | } |
s1340735 | 60:7b5ca1a4d7c3 | 176 | |
s1340735 | 60:7b5ca1a4d7c3 | 177 | Ticker log_timer,; //bicep logtimer |
s1340735 | 60:7b5ca1a4d7c3 | 178 | //set up filters. Use external array for constants |
s1340735 | 60:7b5ca1a4d7c3 | 179 | arm_biquad_cascade_df1_init_f32(&lowpass,1 , lowpass_const, lowpass_states); |
s1340735 | 60:7b5ca1a4d7c3 | 180 | arm_biquad_cascade_df1_init_f32(&highpass,1 ,highpass_const, highpass_states); |
s1340735 | 60:7b5ca1a4d7c3 | 181 | |
s1340735 | 60:7b5ca1a4d7c3 | 182 | /**Here you attach the 'void looper(void)' function to the Ticker object |
s1340735 | 60:7b5ca1a4d7c3 | 183 | * The looper() function will be called every 0.01 seconds. |
s1340735 | 60:7b5ca1a4d7c3 | 184 | * Please mind that the parentheses after looper are omitted when using attach. |
s1340735 | 60:7b5ca1a4d7c3 | 185 | */ |
Tanja2211 | 45:7950fa411107 | 186 | log_timer.attach(looperT, 0.005);//?? |
Tanja2211 | 45:7950fa411107 | 187 | while(1) { //Loop |
Tanja2211 | 45:7950fa411107 | 188 | /*Empty!*/ |
Tanja2211 | 45:7950fa411107 | 189 | /*Everything is handled by the interrupt routine now!*/ |
s1340735 | 23:1c51af8386c9 | 190 | } |
s1340735 | 60:7b5ca1a4d7c3 | 191 | |
Tanja2211 | 45:7950fa411107 | 192 | } |
s1340735 | 23:1c51af8386c9 | 193 | |
Tanja2211 | 52:cce270e0753a | 194 | void AntwoordT() |
Tanja2211 | 45:7950fa411107 | 195 | { |
Tanja2211 | 54:f3a9fa5f2b0e | 196 | drempelwaardeT1=4.99; |
Tanja2211 | 54:f3a9fa5f2b0e | 197 | drempelwaardeT2=7; |
Tanja2211 | 54:f3a9fa5f2b0e | 198 | int yT1, yT2; |
Tanja2211 | 58:b5bb78380767 | 199 | |
Tanja2211 | 58:b5bb78380767 | 200 | if (MOVAVG_T > drempelwaardeT1) { |
Tanja2211 | 58:b5bb78380767 | 201 | yT1=1; |
Tanja2211 | 58:b5bb78380767 | 202 | if (MOVAVG_T > drempelwaardeT2) { |
Tanja2211 | 54:f3a9fa5f2b0e | 203 | yT2=1; |
Tanja2211 | 54:f3a9fa5f2b0e | 204 | } else { |
Tanja2211 | 58:b5bb78380767 | 205 | yT2=0; |
Tanja2211 | 54:f3a9fa5f2b0e | 206 | } |
Tanja2211 | 58:b5bb78380767 | 207 | } else { |
Tanja2211 | 58:b5bb78380767 | 208 | yT1=0; |
Tanja2211 | 58:b5bb78380767 | 209 | } |
Tanja2211 | 58:b5bb78380767 | 210 | |
Tanja2211 | 58:b5bb78380767 | 211 | int positie; |
Tanja2211 | 58:b5bb78380767 | 212 | |
Tanja2211 | 58:b5bb78380767 | 213 | positie=yT1+yT2; |
Tanja2211 | 58:b5bb78380767 | 214 | if (positie==0) { |
Tanja2211 | 58:b5bb78380767 | 215 | pc.printf("Motor 2 beweegt niet\n"); |
Tanja2211 | 58:b5bb78380767 | 216 | } else { |
Tanja2211 | 58:b5bb78380767 | 217 | pc.printf("Motor 2 gaat beweegen\n"); |
Tanja2211 | 58:b5bb78380767 | 218 | } |
Tanja2211 | 58:b5bb78380767 | 219 | if (positie==1) { |
Tanja2211 | 58:b5bb78380767 | 220 | pc.printf("Motor 2 beweegt naar positie 1\n"); |
Tanja2211 | 58:b5bb78380767 | 221 | } else { |
Tanja2211 | 58:b5bb78380767 | 222 | pc.printf("Motor 1 beweegt niet naar positie 1\n"); |
Tanja2211 | 58:b5bb78380767 | 223 | } |
Tanja2211 | 58:b5bb78380767 | 224 | if (positie==2) { |
Tanja2211 | 58:b5bb78380767 | 225 | pc.printf("Motor 1 beweegt naar positie 2\n"); |
Tanja2211 | 58:b5bb78380767 | 226 | } else { |
Tanja2211 | 58:b5bb78380767 | 227 | pc.printf("Motor 1 beweegt niet naar positie 2\n"); |
Tanja2211 | 58:b5bb78380767 | 228 | } |
Tanja2211 | 58:b5bb78380767 | 229 | } |
Tanja2211 | 38:7ed04177892b | 230 | |
s1340735 | 60:7b5ca1a4d7c3 | 231 | void AntwoordB() |
s1340735 | 60:7b5ca1a4d7c3 | 232 | { |
s1340735 | 60:7b5ca1a4d7c3 | 233 | drempelwaardeB1=4.99; |
s1340735 | 60:7b5ca1a4d7c3 | 234 | drempelwaardeB2=6; |
s1340735 | 60:7b5ca1a4d7c3 | 235 | drempelwaardeB3=10; |
s1340735 | 60:7b5ca1a4d7c3 | 236 | int yB1; |
s1340735 | 60:7b5ca1a4d7c3 | 237 | int yB2; |
s1340735 | 60:7b5ca1a4d7c3 | 238 | int yB3; |
Tanja2211 | 38:7ed04177892b | 239 | |
s1340735 | 60:7b5ca1a4d7c3 | 240 | if (MOVAVG_B > drempelwaardeB1) { |
s1340735 | 60:7b5ca1a4d7c3 | 241 | yB1=1; |
s1340735 | 60:7b5ca1a4d7c3 | 242 | if (MOVAVG_B > drempelwaardeB2) { |
s1340735 | 60:7b5ca1a4d7c3 | 243 | yB2=1; |
s1340735 | 60:7b5ca1a4d7c3 | 244 | if (MOVAVG_B > drempelwaardeB3) { |
s1340735 | 60:7b5ca1a4d7c3 | 245 | yB3=1; |
Tanja2211 | 58:b5bb78380767 | 246 | } else { |
s1340735 | 60:7b5ca1a4d7c3 | 247 | yB3=0; |
Tanja2211 | 58:b5bb78380767 | 248 | } |
Tanja2211 | 45:7950fa411107 | 249 | } else { |
s1340735 | 60:7b5ca1a4d7c3 | 250 | yB2=0; |
Tanja2211 | 45:7950fa411107 | 251 | } |
s1340735 | 60:7b5ca1a4d7c3 | 252 | } else { |
s1340735 | 60:7b5ca1a4d7c3 | 253 | yB1=0; |
s1340735 | 60:7b5ca1a4d7c3 | 254 | } |
s1340735 | 60:7b5ca1a4d7c3 | 255 | |
s1340735 | 60:7b5ca1a4d7c3 | 256 | int snelheidsstand; |
s1340735 | 60:7b5ca1a4d7c3 | 257 | |
s1340735 | 60:7b5ca1a4d7c3 | 258 | snelheidsstand=yB1+yB2+yB3; |
s1340735 | 60:7b5ca1a4d7c3 | 259 | if (snelheidsstand==1) { |
s1340735 | 60:7b5ca1a4d7c3 | 260 | pc.printf("Motor 1 beweegt met snelheid 1\n"); |
s1340735 | 60:7b5ca1a4d7c3 | 261 | } else { |
s1340735 | 60:7b5ca1a4d7c3 | 262 | pc.printf("Motor 1 beweegt niet met snelheid 1\n"); |
Tanja2211 | 58:b5bb78380767 | 263 | } |
s1340735 | 60:7b5ca1a4d7c3 | 264 | if (snelheidsstand==2) { |
s1340735 | 60:7b5ca1a4d7c3 | 265 | pc.printf("Motor 1 beweegt met snelheid 2\n"); |
s1340735 | 60:7b5ca1a4d7c3 | 266 | } else { |
s1340735 | 60:7b5ca1a4d7c3 | 267 | pc.printf("Motor 1 beweegt niet met snelheid 2\n"); |
s1340735 | 60:7b5ca1a4d7c3 | 268 | } |
s1340735 | 60:7b5ca1a4d7c3 | 269 | if (snelheidsstand==3) { |
s1340735 | 60:7b5ca1a4d7c3 | 270 | pc.printf("Motor 1 beweegt met snelheid 3\n"); |
s1340735 | 60:7b5ca1a4d7c3 | 271 | } else { |
s1340735 | 60:7b5ca1a4d7c3 | 272 | pc.printf("Motor 1 beweegt niet met snelheid 3\n"); |
s1340735 | 60:7b5ca1a4d7c3 | 273 | } |
s1340735 | 60:7b5ca1a4d7c3 | 274 | } |