Yea it is working. done programinging for a while!

Dependencies:   HIDScope QEI mbed

Committer:
yohoo15
Date:
Thu Oct 29 14:29:21 2015 +0000
Revision:
1:267ff9a39ee4
Parent:
0:0f08f98ae7f8
Child:
2:e84adf0a960f
finalized with song and other buttons;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yohoo15 0:0f08f98ae7f8 1 #include "mbed.h"
yohoo15 0:0f08f98ae7f8 2 //#include "read_filter_emg.h"
yohoo15 0:0f08f98ae7f8 3 //included for fabs() function
yohoo15 0:0f08f98ae7f8 4 #include <math.h>
yohoo15 0:0f08f98ae7f8 5 #include "HIDScope.h"
yohoo15 0:0f08f98ae7f8 6 #include <iostream>
yohoo15 0:0f08f98ae7f8 7 #include "QEI.h"
yohoo15 0:0f08f98ae7f8 8
yohoo15 0:0f08f98ae7f8 9 //DigitalOut led_green(LED_GREEN);
yohoo15 0:0f08f98ae7f8 10 //DigitalOut led_red(LED_RED);
yohoo15 0:0f08f98ae7f8 11
yohoo15 0:0f08f98ae7f8 12 Serial pc(USBTX, USBRX);
yohoo15 0:0f08f98ae7f8 13 AnalogIn analog_emg_left(A0);
yohoo15 0:0f08f98ae7f8 14 AnalogIn analog_emg_right(A1);
yohoo15 0:0f08f98ae7f8 15
yohoo15 0:0f08f98ae7f8 16 Ticker HIDScope_timer;
yohoo15 0:0f08f98ae7f8 17 Ticker Filteren_timer;
yohoo15 0:0f08f98ae7f8 18 Ticker aansturen;
yohoo15 0:0f08f98ae7f8 19
yohoo15 0:0f08f98ae7f8 20 HIDScope scope(4);
yohoo15 0:0f08f98ae7f8 21
yohoo15 0:0f08f98ae7f8 22 // defining flags
yohoo15 0:0f08f98ae7f8 23 volatile bool Flag_filteren = false;
yohoo15 0:0f08f98ae7f8 24 volatile bool Flag_HIDScope = false;
yohoo15 0:0f08f98ae7f8 25 volatile bool left_movement = false;
yohoo15 0:0f08f98ae7f8 26 volatile bool right_movement = false;
yohoo15 0:0f08f98ae7f8 27
yohoo15 0:0f08f98ae7f8 28 // making function flags.
yohoo15 0:0f08f98ae7f8 29 void Go_flag_filteren()
yohoo15 0:0f08f98ae7f8 30 {
yohoo15 0:0f08f98ae7f8 31 Flag_filteren = true;
yohoo15 0:0f08f98ae7f8 32 }
yohoo15 0:0f08f98ae7f8 33
yohoo15 0:0f08f98ae7f8 34 void Go_flag_HIDScope()
yohoo15 0:0f08f98ae7f8 35 {
yohoo15 0:0f08f98ae7f8 36 Flag_HIDScope = true;
yohoo15 0:0f08f98ae7f8 37 }
yohoo15 0:0f08f98ae7f8 38
yohoo15 0:0f08f98ae7f8 39
yohoo15 0:0f08f98ae7f8 40
yohoo15 0:0f08f98ae7f8 41 double input_left = 0 ;
yohoo15 0:0f08f98ae7f8 42 double input_right = 0 ;
yohoo15 0:0f08f98ae7f8 43 //double input = 0;
yohoo15 0:0f08f98ae7f8 44 double filter_signal_hid_left = 0;
yohoo15 0:0f08f98ae7f8 45 double filter_signal_hid_right = 0;
yohoo15 0:0f08f98ae7f8 46 //double input_right = 0;
yohoo15 0:0f08f98ae7f8 47 // defining threshold
yohoo15 1:267ff9a39ee4 48 double high_threshold = 1000;
yohoo15 0:0f08f98ae7f8 49 double low_threshold = 125;
yohoo15 0:0f08f98ae7f8 50
yohoo15 0:0f08f98ae7f8 51 //*** making the v for everything and conquer the world***
yohoo15 0:0f08f98ae7f8 52
yohoo15 0:0f08f98ae7f8 53 //for left
yohoo15 0:0f08f98ae7f8 54 //for Notchfilter
yohoo15 0:0f08f98ae7f8 55 double notch_v11=0;
yohoo15 0:0f08f98ae7f8 56 double notch_v21=0;
yohoo15 0:0f08f98ae7f8 57 double notch_v12=0;
yohoo15 0:0f08f98ae7f8 58 double notch_v22=0;
yohoo15 0:0f08f98ae7f8 59 double notch_v13=0;
yohoo15 0:0f08f98ae7f8 60 double notch_v23=0;
yohoo15 0:0f08f98ae7f8 61
yohoo15 0:0f08f98ae7f8 62 //for highpass filter
yohoo15 0:0f08f98ae7f8 63 double high_v11=0;
yohoo15 0:0f08f98ae7f8 64 double high_v21=0;
yohoo15 0:0f08f98ae7f8 65 double high_v12=0;
yohoo15 0:0f08f98ae7f8 66 double high_v22=0;
yohoo15 0:0f08f98ae7f8 67 double high_v13=0;
yohoo15 0:0f08f98ae7f8 68 double high_v23=0;
yohoo15 0:0f08f98ae7f8 69
yohoo15 0:0f08f98ae7f8 70 // for lowpasfilter
yohoo15 0:0f08f98ae7f8 71 double low_v11=0;
yohoo15 0:0f08f98ae7f8 72 double low_v21=0;
yohoo15 0:0f08f98ae7f8 73 double low_v12=0;
yohoo15 0:0f08f98ae7f8 74 double low_v22=0;
yohoo15 0:0f08f98ae7f8 75 double low_v13=0;
yohoo15 0:0f08f98ae7f8 76 double low_v23=0;
yohoo15 0:0f08f98ae7f8 77
yohoo15 0:0f08f98ae7f8 78 // for moving average
yohoo15 0:0f08f98ae7f8 79 double n1 = 0;
yohoo15 0:0f08f98ae7f8 80 double n2 = 0;
yohoo15 0:0f08f98ae7f8 81 double n3 = 0;
yohoo15 0:0f08f98ae7f8 82 double n4 = 0;
yohoo15 0:0f08f98ae7f8 83 double n5 = 0;
yohoo15 0:0f08f98ae7f8 84
yohoo15 0:0f08f98ae7f8 85 // for right
yohoo15 0:0f08f98ae7f8 86 //for Notchfilter
yohoo15 0:0f08f98ae7f8 87 double notch_v11_b=0;
yohoo15 0:0f08f98ae7f8 88 double notch_v21_b=0;
yohoo15 0:0f08f98ae7f8 89 double notch_v12_b=0;
yohoo15 0:0f08f98ae7f8 90 double notch_v22_b=0;
yohoo15 0:0f08f98ae7f8 91 double notch_v13_b=0;
yohoo15 0:0f08f98ae7f8 92 double notch_v23_b=0;
yohoo15 0:0f08f98ae7f8 93
yohoo15 0:0f08f98ae7f8 94 //for highpass filter
yohoo15 0:0f08f98ae7f8 95 double high_v11_b=0;
yohoo15 0:0f08f98ae7f8 96 double high_v21_b=0;
yohoo15 0:0f08f98ae7f8 97 double high_v12_b=0;
yohoo15 0:0f08f98ae7f8 98 double high_v22_b=0;
yohoo15 0:0f08f98ae7f8 99 double high_v13_b=0;
yohoo15 0:0f08f98ae7f8 100 double high_v23_b=0;
yohoo15 0:0f08f98ae7f8 101
yohoo15 0:0f08f98ae7f8 102 // for lowpasfilter
yohoo15 0:0f08f98ae7f8 103 double low_v11_b=0;
yohoo15 0:0f08f98ae7f8 104 double low_v21_b=0;
yohoo15 0:0f08f98ae7f8 105 double low_v12_b=0;
yohoo15 0:0f08f98ae7f8 106 double low_v22_b=0;
yohoo15 0:0f08f98ae7f8 107 double low_v13_b=0;
yohoo15 0:0f08f98ae7f8 108 double low_v23_b=0;
yohoo15 0:0f08f98ae7f8 109
yohoo15 0:0f08f98ae7f8 110 // for moving average
yohoo15 0:0f08f98ae7f8 111 double n1_b = 0;
yohoo15 0:0f08f98ae7f8 112 double n2_b = 0;
yohoo15 0:0f08f98ae7f8 113 double n3_b = 0;
yohoo15 0:0f08f98ae7f8 114 double n4_b = 0;
yohoo15 0:0f08f98ae7f8 115 double n5_b = 0;
yohoo15 0:0f08f98ae7f8 116
yohoo15 0:0f08f98ae7f8 117
yohoo15 0:0f08f98ae7f8 118 double filter_left;
yohoo15 0:0f08f98ae7f8 119 double filter_right;
yohoo15 0:0f08f98ae7f8 120
yohoo15 0:0f08f98ae7f8 121 //general biquad filter that can be called in all the filter functions
yohoo15 0:0f08f98ae7f8 122 double biquad(double u, double &v1, double &v2, const double a1,
yohoo15 0:0f08f98ae7f8 123 const double a2, const double b0, const double b1, const double b2)
yohoo15 0:0f08f98ae7f8 124 {
yohoo15 0:0f08f98ae7f8 125 double v = u - a1*v1 - a2*v2;
yohoo15 0:0f08f98ae7f8 126 double y = b0*v + b1*v1 + b2*v2;
yohoo15 0:0f08f98ae7f8 127 //values of v2 and v1 are updated, as they are passed by reference
yohoo15 0:0f08f98ae7f8 128 //they update globally
yohoo15 0:0f08f98ae7f8 129 v2 = v1;
yohoo15 0:0f08f98ae7f8 130 v1 = v;
yohoo15 0:0f08f98ae7f8 131 return y;
yohoo15 0:0f08f98ae7f8 132 }
yohoo15 0:0f08f98ae7f8 133
yohoo15 0:0f08f98ae7f8 134 double moving_average(double y, double &n1, double &n2, double &n3, double &n4, double &n5)
yohoo15 0:0f08f98ae7f8 135 {
yohoo15 0:0f08f98ae7f8 136 double average = (y + n1 + n2 +n3 + n4 + n5)/5;
yohoo15 0:0f08f98ae7f8 137 n5 = n4;
yohoo15 0:0f08f98ae7f8 138 n4 = n3;
yohoo15 0:0f08f98ae7f8 139 n3 = n2;
yohoo15 0:0f08f98ae7f8 140 n2 = n1;
yohoo15 0:0f08f98ae7f8 141 n1 = y;
yohoo15 0:0f08f98ae7f8 142
yohoo15 0:0f08f98ae7f8 143 return average;
yohoo15 0:0f08f98ae7f8 144 }
yohoo15 0:0f08f98ae7f8 145 /*
yohoo15 0:0f08f98ae7f8 146 double threshold(double signal, const double lowtreshold, const double hightreshold)
yohoo15 0:0f08f98ae7f8 147 {
yohoo15 0:0f08f98ae7f8 148 if (signal > hightreshold)
yohoo15 0:0f08f98ae7f8 149 left = true;
yohoo15 0:0f08f98ae7f8 150 else if (signal <lowtreshold)
yohoo15 0:0f08f98ae7f8 151 left = false;
yohoo15 0:0f08f98ae7f8 152 }
yohoo15 0:0f08f98ae7f8 153 */
yohoo15 0:0f08f98ae7f8 154 //Specifying filter coefficients highpass
yohoo15 0:0f08f98ae7f8 155
yohoo15 0:0f08f98ae7f8 156 /* notch filter with 3 cascaded biquads*/
yohoo15 0:0f08f98ae7f8 157 //first notch biquad
yohoo15 0:0f08f98ae7f8 158 const double notch1_a1 = -1.55951422433;
yohoo15 0:0f08f98ae7f8 159 const double notch1_a2 = 0.92705680308;
yohoo15 0:0f08f98ae7f8 160 const double notch1_b0 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 161 const double notch1_b1 = -1.61854515325;
yohoo15 0:0f08f98ae7f8 162 const double notch1_b2 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 163
yohoo15 0:0f08f98ae7f8 164 //second notch biquad
yohoo15 0:0f08f98ae7f8 165 const double notch2_a1 = -1.54767435801;
yohoo15 0:0f08f98ae7f8 166 const double notch2_a2 = 0.96124842048;
yohoo15 0:0f08f98ae7f8 167 const double notch2_b0 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 168 const double notch2_b1 = -1.61854515325;
yohoo15 0:0f08f98ae7f8 169 const double notch2_b2 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 170
yohoo15 0:0f08f98ae7f8 171 //third notch biquad
yohoo15 0:0f08f98ae7f8 172 const double notch3_a1 = -1.62600366964;
yohoo15 0:0f08f98ae7f8 173 const double notch3_a2 = 0.96453460373;
yohoo15 0:0f08f98ae7f8 174 const double notch3_b0 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 175 const double notch3_b1 = -1.61854515325;
yohoo15 0:0f08f98ae7f8 176 const double notch3_b2 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 177
yohoo15 0:0f08f98ae7f8 178 /* high pass filter consists of three cascaded biquads
yohoo15 0:0f08f98ae7f8 179 blow coefficients for those three biquads */
yohoo15 0:0f08f98ae7f8 180 //first high pass biquad
yohoo15 0:0f08f98ae7f8 181 const double highp1_a1 = -0.67538034389;
yohoo15 0:0f08f98ae7f8 182 const double highp1_a2 = 0.12769255668;
yohoo15 0:0f08f98ae7f8 183 const double highp1_b0 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 184 const double highp1_b1 = -2.00000000000;
yohoo15 0:0f08f98ae7f8 185 const double highp1_b2 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 186
yohoo15 0:0f08f98ae7f8 187 //second high pass biquad
yohoo15 0:0f08f98ae7f8 188 const double highp2_a1 = -0.76475499450;
yohoo15 0:0f08f98ae7f8 189 const double highp2_a2 = 0.27692273367;
yohoo15 0:0f08f98ae7f8 190 const double highp2_b0 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 191 const double highp2_b1 = -2.00000000000;
yohoo15 0:0f08f98ae7f8 192 const double highp2_b2 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 193
yohoo15 0:0f08f98ae7f8 194 //third high pass biquad
yohoo15 0:0f08f98ae7f8 195 const double highp3_a1 = -0.99216561242;
yohoo15 0:0f08f98ae7f8 196 const double highp3_a2 = 0.65663360837;
yohoo15 0:0f08f98ae7f8 197 const double highp3_b0 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 198 const double highp3_b1 = -2.00000000000;
yohoo15 0:0f08f98ae7f8 199 const double highp3_b2 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 200
yohoo15 0:0f08f98ae7f8 201 /* lowpass filter consists of three cascaded biquads
yohoo15 0:0f08f98ae7f8 202 below the coefficients for those three biquads */
yohoo15 0:0f08f98ae7f8 203 //first low pass biquad
yohoo15 0:0f08f98ae7f8 204 const double lowp1_a1 = -1.05207469728;
yohoo15 0:0f08f98ae7f8 205 const double lowp1_a2 = 0.28586907478;
yohoo15 0:0f08f98ae7f8 206 const double lowp1_b0 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 207 const double lowp1_b1 = 2.00000000000;
yohoo15 0:0f08f98ae7f8 208 const double lowp1_b2 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 209
yohoo15 0:0f08f98ae7f8 210 //second low pass biquad
yohoo15 0:0f08f98ae7f8 211 const double lowp2_a1 = -1.16338171052;
yohoo15 0:0f08f98ae7f8 212 const double lowp2_a2 = 0.42191097989;
yohoo15 0:0f08f98ae7f8 213 const double lowp2_b0 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 214 const double lowp2_b1 = 2.00000000000;
yohoo15 0:0f08f98ae7f8 215 const double lowp2_b2 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 216
yohoo15 0:0f08f98ae7f8 217 //third low pass biquad
yohoo15 0:0f08f98ae7f8 218 const double lowp3_a1 = -1.42439823874;
yohoo15 0:0f08f98ae7f8 219 const double lowp3_a2 = 0.74093118112;
yohoo15 0:0f08f98ae7f8 220 const double lowp3_b0 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 221 const double lowp3_b1 = 2.00000000000;
yohoo15 0:0f08f98ae7f8 222 const double lowp3_b2 = 1.00000000000;
yohoo15 0:0f08f98ae7f8 223
yohoo15 0:0f08f98ae7f8 224
yohoo15 0:0f08f98ae7f8 225
yohoo15 0:0f08f98ae7f8 226 double Filteren_left(double input)
yohoo15 0:0f08f98ae7f8 227 {
yohoo15 0:0f08f98ae7f8 228
yohoo15 0:0f08f98ae7f8 229 input = input-0.45; //FIRST SUBTRACT MEAN THEN FILTER
yohoo15 0:0f08f98ae7f8 230 //input_right = analog_emg_right.read();
yohoo15 0:0f08f98ae7f8 231
yohoo15 0:0f08f98ae7f8 232 // notch filter
yohoo15 0:0f08f98ae7f8 233 double y1 = biquad(input, notch_v11, notch_v21, notch1_a1, notch1_a2, notch1_b0, notch1_b1, notch1_b2);
yohoo15 0:0f08f98ae7f8 234 double y2 = biquad(y1, notch_v12, notch_v22, notch2_a1, notch2_a2, notch2_b0, notch2_b1, notch2_b2);
yohoo15 0:0f08f98ae7f8 235 double y3 = biquad(y2, notch_v13, notch_v23, notch3_a1, notch3_a2, notch3_b0, notch3_b1, notch3_b2);
yohoo15 0:0f08f98ae7f8 236
yohoo15 0:0f08f98ae7f8 237 //higpass filter
yohoo15 0:0f08f98ae7f8 238 double y4 = biquad(y3, high_v11, high_v21, highp1_a1, highp1_a2, highp1_b0, highp1_b1, highp1_b2);
yohoo15 0:0f08f98ae7f8 239 double y5 = biquad(y4, high_v12, high_v22, highp2_a1, highp2_a2, highp2_b0, highp2_b1, highp2_b2);
yohoo15 0:0f08f98ae7f8 240 double y6 = biquad(y5, high_v13, high_v23, highp3_a1, highp3_a2, highp3_b0, highp3_b1, highp3_b2);
yohoo15 0:0f08f98ae7f8 241
yohoo15 0:0f08f98ae7f8 242 //rectivier
yohoo15 0:0f08f98ae7f8 243 double y7 = fabs(y6);
yohoo15 0:0f08f98ae7f8 244
yohoo15 0:0f08f98ae7f8 245 //lowpas filter cascade
yohoo15 0:0f08f98ae7f8 246 double y8 = biquad(y7, low_v11, low_v21, lowp1_a1, lowp1_a2, lowp1_b0, lowp1_b1, lowp1_b2);
yohoo15 0:0f08f98ae7f8 247 double y9 = biquad(y8, low_v12, low_v22, lowp2_a1, lowp2_a2, lowp2_b0, lowp2_b1, lowp2_b2);
yohoo15 0:0f08f98ae7f8 248 double y10= biquad(y9, low_v13, low_v23, lowp3_a1, lowp3_a2, lowp3_b0, lowp3_b1, lowp3_b2);
yohoo15 0:0f08f98ae7f8 249
yohoo15 0:0f08f98ae7f8 250 // moving average
yohoo15 0:0f08f98ae7f8 251 double filter_signal = moving_average(y10,n1,n2,n3,n4,n5);
yohoo15 0:0f08f98ae7f8 252
yohoo15 0:0f08f98ae7f8 253 return(filter_signal);
yohoo15 0:0f08f98ae7f8 254 }
yohoo15 0:0f08f98ae7f8 255
yohoo15 0:0f08f98ae7f8 256 double Filteren_right(double input_b)
yohoo15 0:0f08f98ae7f8 257 {
yohoo15 0:0f08f98ae7f8 258
yohoo15 0:0f08f98ae7f8 259 input_b = input_b-0.45; //FIRST SUBTRACT MEAN THEN FILTER
yohoo15 0:0f08f98ae7f8 260 //input_right = analog_emg_right.read();
yohoo15 0:0f08f98ae7f8 261
yohoo15 0:0f08f98ae7f8 262 // notch filter
yohoo15 0:0f08f98ae7f8 263 double y1_b = biquad(input_b, notch_v11_b, notch_v21_b, notch1_a1, notch1_a2, notch1_b0, notch1_b1, notch1_b2);
yohoo15 0:0f08f98ae7f8 264 double y2_b = biquad(y1_b, notch_v12_b, notch_v22_b, notch2_a1, notch2_a2, notch2_b0, notch2_b1, notch2_b2);
yohoo15 0:0f08f98ae7f8 265 double y3_b = biquad(y2_b, notch_v13_b, notch_v23_b, notch3_a1, notch3_a2, notch3_b0, notch3_b1, notch3_b2);
yohoo15 0:0f08f98ae7f8 266
yohoo15 0:0f08f98ae7f8 267 //higpass filter
yohoo15 0:0f08f98ae7f8 268 double y4_b = biquad(y3_b, high_v11_b, high_v21_b, highp1_a1, highp1_a2, highp1_b0, highp1_b1, highp1_b2);
yohoo15 0:0f08f98ae7f8 269 double y5_b = biquad(y4_b, high_v12_b, high_v22_b, highp2_a1, highp2_a2, highp2_b0, highp2_b1, highp2_b2);
yohoo15 0:0f08f98ae7f8 270 double y6_b = biquad(y5_b, high_v13_b, high_v23_b, highp3_a1, highp3_a2, highp3_b0, highp3_b1, highp3_b2);
yohoo15 0:0f08f98ae7f8 271
yohoo15 0:0f08f98ae7f8 272 //rectivier
yohoo15 0:0f08f98ae7f8 273 double y7_b = fabs(y6_b);
yohoo15 0:0f08f98ae7f8 274
yohoo15 0:0f08f98ae7f8 275 //lowpas filter cascade
yohoo15 0:0f08f98ae7f8 276 double y8_b = biquad(y7_b, low_v11_b, low_v21_b, lowp1_a1, lowp1_a2, lowp1_b0, lowp1_b1, lowp1_b2);
yohoo15 0:0f08f98ae7f8 277 double y9_b = biquad(y8_b, low_v12_b, low_v22_b, lowp2_a1, lowp2_a2, lowp2_b0, lowp2_b1, lowp2_b2);
yohoo15 0:0f08f98ae7f8 278 double y10_b= biquad(y9_b, low_v13_b, low_v23_b, lowp3_a1, lowp3_a2, lowp3_b0, lowp3_b1, lowp3_b2);
yohoo15 0:0f08f98ae7f8 279
yohoo15 0:0f08f98ae7f8 280 // moving average
yohoo15 0:0f08f98ae7f8 281 double filter_signal_b = moving_average(y10_b,n1_b,n2_b,n3_b,n4_b,n5_b);
yohoo15 0:0f08f98ae7f8 282
yohoo15 0:0f08f98ae7f8 283 return(filter_signal_b);
yohoo15 0:0f08f98ae7f8 284 }
yohoo15 0:0f08f98ae7f8 285
yohoo15 0:0f08f98ae7f8 286 /*************************************************************BEGIN motor control******************************************************************************************************/
yohoo15 0:0f08f98ae7f8 287 // Define pin for motor control
yohoo15 0:0f08f98ae7f8 288 DigitalOut directionPin(D4);
yohoo15 0:0f08f98ae7f8 289 PwmOut PWM(D5);
yohoo15 0:0f08f98ae7f8 290 DigitalOut directionPin_key(D7);
yohoo15 0:0f08f98ae7f8 291 PwmOut PWM_key(D6);
yohoo15 0:0f08f98ae7f8 292 Ticker both_timer;
yohoo15 0:0f08f98ae7f8 293 // define rotation direction and begin possition
yohoo15 0:0f08f98ae7f8 294 const int cw = 1;
yohoo15 0:0f08f98ae7f8 295 const int ccw = 0;
yohoo15 0:0f08f98ae7f8 296
yohoo15 0:0f08f98ae7f8 297 volatile bool flag_both = false;
yohoo15 0:0f08f98ae7f8 298
yohoo15 0:0f08f98ae7f8 299 // making function flags.
yohoo15 0:0f08f98ae7f8 300 void Go_flag_both()
yohoo15 0:0f08f98ae7f8 301 {
yohoo15 0:0f08f98ae7f8 302 flag_both = true;
yohoo15 0:0f08f98ae7f8 303 }
yohoo15 0:0f08f98ae7f8 304
yohoo15 0:0f08f98ae7f8 305
yohoo15 0:0f08f98ae7f8 306 /*
yohoo15 0:0f08f98ae7f8 307 double Rotation = -2; // rotation
yohoo15 0:0f08f98ae7f8 308 double movement = Rotation * pulses_per_revolution; // times 360 to make Rotations degree.
yohoo15 0:0f08f98ae7f8 309 */
yohoo15 0:0f08f98ae7f8 310
yohoo15 0:0f08f98ae7f8 311
yohoo15 0:0f08f98ae7f8 312 /*
yohoo15 0:0f08f98ae7f8 313
yohoo15 0:0f08f98ae7f8 314 // Reusable P controller
yohoo15 0:0f08f98ae7f8 315 double PI(double error, const double Kp, const double Ki, double Ts, double &e_int)
yohoo15 0:0f08f98ae7f8 316 {
yohoo15 0:0f08f98ae7f8 317
yohoo15 0:0f08f98ae7f8 318 e_int = e_int + Ts * error;
yohoo15 0:0f08f98ae7f8 319
yohoo15 0:0f08f98ae7f8 320 double PI_output = (Kp * error) + (Ki * e_int);
yohoo15 0:0f08f98ae7f8 321 return PI_output;
yohoo15 0:0f08f98ae7f8 322 }
yohoo15 0:0f08f98ae7f8 323 // Next task, measure the error and apply the output to the plant
yohoo15 0:0f08f98ae7f8 324
yohoo15 0:0f08f98ae7f8 325 // control for movement left right
yohoo15 0:0f08f98ae7f8 326 void motor1_Controller()
yohoo15 0:0f08f98ae7f8 327 {
yohoo15 0:0f08f98ae7f8 328 double reference = setpoint; // setpoint is in pulses
yohoo15 0:0f08f98ae7f8 329 double position = wheel.getPulses();
yohoo15 0:0f08f98ae7f8 330 double error_pulses = (reference - position); // calculate the error in pulses
yohoo15 0:0f08f98ae7f8 331 double error_rotation = error_pulses / pulses_per_revolution; //calculate how much the rotaions the motor has to turn
yohoo15 0:0f08f98ae7f8 332
yohoo15 0:0f08f98ae7f8 333 double output = abs(PI( error_rotation, motor1_Kp, motor1_Ki, M1_timestep, motor1_error_integraal ));
yohoo15 0:0f08f98ae7f8 334
yohoo15 0:0f08f98ae7f8 335 if(error_pulses > 0) {
yohoo15 0:0f08f98ae7f8 336 directionPin.write(cw);
yohoo15 0:0f08f98ae7f8 337
yohoo15 0:0f08f98ae7f8 338 } else if(error_pulses < 0) {
yohoo15 0:0f08f98ae7f8 339 directionPin.write(ccw);
yohoo15 0:0f08f98ae7f8 340 } else {
yohoo15 0:0f08f98ae7f8 341 output = 0;
yohoo15 0:0f08f98ae7f8 342 }
yohoo15 0:0f08f98ae7f8 343 PWM.write(output); // out of the if loop due to abs output
yohoo15 0:0f08f98ae7f8 344
yohoo15 0:0f08f98ae7f8 345
yohoo15 0:0f08f98ae7f8 346 }*/
yohoo15 0:0f08f98ae7f8 347
yohoo15 0:0f08f98ae7f8 348 /*************************************************************END motor control******************************************************************************************************/
yohoo15 1:267ff9a39ee4 349 /*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
yohoo15 1:267ff9a39ee4 350 /*************************************************************BEGIN switch******************************************************************************************************/
yohoo15 1:267ff9a39ee4 351 //button to press the key
yohoo15 1:267ff9a39ee4 352 DigitalIn button_only_key(PTC6);
yohoo15 1:267ff9a39ee4 353 DigitalIn button_demo(PTA4);
yohoo15 1:267ff9a39ee4 354 DigitalIn button_song(PTB9);
yohoo15 1:267ff9a39ee4 355 DigitalIn button_do_nothing(PTD1);
yohoo15 0:0f08f98ae7f8 356
yohoo15 1:267ff9a39ee4 357 //int to check if the button is pressed
yohoo15 1:267ff9a39ee4 358 const int Button_only_key_on = 0;
yohoo15 1:267ff9a39ee4 359 const int Button_demo_on = 0;
yohoo15 1:267ff9a39ee4 360 const int Button_song_on = 0;
yohoo15 1:267ff9a39ee4 361 const int Button_do_nothing_on = 0;
yohoo15 1:267ff9a39ee4 362
yohoo15 1:267ff9a39ee4 363 volatile bool only_key = false;
yohoo15 1:267ff9a39ee4 364 volatile bool demo = false ;
yohoo15 1:267ff9a39ee4 365
yohoo15 1:267ff9a39ee4 366
yohoo15 1:267ff9a39ee4 367 /*************************************************************END switch******************************************************************************************************/
yohoo15 0:0f08f98ae7f8 368 void HIDScope_kijken()
yohoo15 0:0f08f98ae7f8 369 {
yohoo15 0:0f08f98ae7f8 370 scope.set(0, analog_emg_left.read());
yohoo15 0:0f08f98ae7f8 371 scope.set(1, filter_signal_hid_left);
yohoo15 0:0f08f98ae7f8 372 scope.set(2, analog_emg_right.read());
yohoo15 0:0f08f98ae7f8 373 scope.set(3, filter_signal_hid_right);
yohoo15 0:0f08f98ae7f8 374 scope.send();
yohoo15 0:0f08f98ae7f8 375 }
yohoo15 0:0f08f98ae7f8 376
yohoo15 0:0f08f98ae7f8 377
yohoo15 0:0f08f98ae7f8 378 int main()
yohoo15 0:0f08f98ae7f8 379 {
yohoo15 0:0f08f98ae7f8 380 pc.printf("at the begin, \n");
yohoo15 0:0f08f98ae7f8 381
yohoo15 0:0f08f98ae7f8 382 HIDScope_timer.attach(&Go_flag_HIDScope, 0.02);//0.02 had worked
yohoo15 0:0f08f98ae7f8 383 Filteren_timer.attach(&Go_flag_filteren,0.04);// 0.04 had worked
yohoo15 0:0f08f98ae7f8 384 both_timer.attach(&Go_flag_both, 2);
yohoo15 0:0f08f98ae7f8 385 while(1) {
yohoo15 0:0f08f98ae7f8 386
yohoo15 0:0f08f98ae7f8 387
yohoo15 0:0f08f98ae7f8 388 if(Flag_filteren) {
yohoo15 0:0f08f98ae7f8 389 Flag_filteren = false;
yohoo15 0:0f08f98ae7f8 390 // filter left and set bool
yohoo15 0:0f08f98ae7f8 391 filter_signal_hid_left = Filteren_left(analog_emg_left.read());
yohoo15 0:0f08f98ae7f8 392
yohoo15 0:0f08f98ae7f8 393 if (filter_signal_hid_left > high_threshold) {
yohoo15 0:0f08f98ae7f8 394 left_movement = true;
yohoo15 0:0f08f98ae7f8 395 } else if (filter_signal_hid_left < low_threshold) {
yohoo15 0:0f08f98ae7f8 396 left_movement = false;
yohoo15 0:0f08f98ae7f8 397 }
yohoo15 0:0f08f98ae7f8 398 // make filter right and set bool
yohoo15 0:0f08f98ae7f8 399 filter_signal_hid_right = Filteren_right(analog_emg_right.read());
yohoo15 0:0f08f98ae7f8 400
yohoo15 0:0f08f98ae7f8 401 if (filter_signal_hid_right > high_threshold) {
yohoo15 0:0f08f98ae7f8 402 right_movement = true;
yohoo15 0:0f08f98ae7f8 403 } else if (filter_signal_hid_right < low_threshold) {
yohoo15 0:0f08f98ae7f8 404 right_movement = false;
yohoo15 0:0f08f98ae7f8 405 }
yohoo15 0:0f08f98ae7f8 406
yohoo15 0:0f08f98ae7f8 407
yohoo15 0:0f08f98ae7f8 408 }
yohoo15 0:0f08f98ae7f8 409
yohoo15 0:0f08f98ae7f8 410
yohoo15 0:0f08f98ae7f8 411
yohoo15 0:0f08f98ae7f8 412 if(Flag_HIDScope) {
yohoo15 0:0f08f98ae7f8 413 Flag_HIDScope = false;
yohoo15 0:0f08f98ae7f8 414 HIDScope_kijken();
yohoo15 0:0f08f98ae7f8 415
yohoo15 0:0f08f98ae7f8 416 }
yohoo15 0:0f08f98ae7f8 417
yohoo15 0:0f08f98ae7f8 418
yohoo15 0:0f08f98ae7f8 419
yohoo15 1:267ff9a39ee4 420 if (button_only_key.read() == Button_only_key_on){
yohoo15 1:267ff9a39ee4 421 demo = false;
yohoo15 1:267ff9a39ee4 422 only_key = true;
yohoo15 1:267ff9a39ee4 423 pc.printf("only key /n");
yohoo15 1:267ff9a39ee4 424 }
yohoo15 1:267ff9a39ee4 425
yohoo15 1:267ff9a39ee4 426
yohoo15 1:267ff9a39ee4 427 if (button_demo.read() == Button_demo_on){
yohoo15 1:267ff9a39ee4 428 only_key = false;
yohoo15 1:267ff9a39ee4 429 demo = true;
yohoo15 1:267ff9a39ee4 430 pc.printf("demo /n");
yohoo15 1:267ff9a39ee4 431 }
yohoo15 1:267ff9a39ee4 432
yohoo15 1:267ff9a39ee4 433 if(demo){
yohoo15 0:0f08f98ae7f8 434 // Pussing buttons to get input signal
yohoo15 0:0f08f98ae7f8 435 if( left_movement and right_movement == false) {
yohoo15 0:0f08f98ae7f8 436 directionPin.write(cw);
yohoo15 0:0f08f98ae7f8 437 PWM.write(1);
yohoo15 0:0f08f98ae7f8 438
yohoo15 0:0f08f98ae7f8 439 } else if(right_movement and left_movement == false ) {
yohoo15 0:0f08f98ae7f8 440 directionPin.write(ccw);
yohoo15 0:0f08f98ae7f8 441 PWM.write(1);
yohoo15 0:0f08f98ae7f8 442 } else {
yohoo15 0:0f08f98ae7f8 443 PWM.write(0);
yohoo15 0:0f08f98ae7f8 444 }
yohoo15 0:0f08f98ae7f8 445
yohoo15 0:0f08f98ae7f8 446 if( left_movement and right_movement and flag_both){
yohoo15 0:0f08f98ae7f8 447 directionPin_key.write(cw);
yohoo15 0:0f08f98ae7f8 448 PWM_key.write(1);
yohoo15 0:0f08f98ae7f8 449 wait(0.14);
yohoo15 0:0f08f98ae7f8 450 PWM_key.write(0);
yohoo15 0:0f08f98ae7f8 451 wait(1);
yohoo15 0:0f08f98ae7f8 452 directionPin_key.write(ccw);
yohoo15 0:0f08f98ae7f8 453 PWM_key.write(1);
yohoo15 0:0f08f98ae7f8 454 wait(0.165f);
yohoo15 0:0f08f98ae7f8 455 PWM_key.write(0);
yohoo15 0:0f08f98ae7f8 456 flag_both = false;
yohoo15 0:0f08f98ae7f8 457 }
yohoo15 0:0f08f98ae7f8 458 else{
yohoo15 0:0f08f98ae7f8 459 PWM_key.write(0);
yohoo15 0:0f08f98ae7f8 460 }
yohoo15 1:267ff9a39ee4 461 }
yohoo15 1:267ff9a39ee4 462
yohoo15 1:267ff9a39ee4 463 if(only_key){
yohoo15 1:267ff9a39ee4 464
yohoo15 1:267ff9a39ee4 465 if(left_movement and flag_both){
yohoo15 1:267ff9a39ee4 466 directionPin_key.write(cw);
yohoo15 1:267ff9a39ee4 467 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 468 wait(0.14);
yohoo15 1:267ff9a39ee4 469 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 470 wait(1);
yohoo15 1:267ff9a39ee4 471 directionPin_key.write(ccw);
yohoo15 1:267ff9a39ee4 472 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 473 wait(0.165f);
yohoo15 1:267ff9a39ee4 474 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 475 flag_both = false;
yohoo15 1:267ff9a39ee4 476
yohoo15 1:267ff9a39ee4 477 }
yohoo15 1:267ff9a39ee4 478 }
yohoo15 1:267ff9a39ee4 479
yohoo15 1:267ff9a39ee4 480 if (button_do_nothing.read() == Button_do_nothing_on){
yohoo15 1:267ff9a39ee4 481 }
yohoo15 1:267ff9a39ee4 482 if (button_song.read() == Button_song_on){
yohoo15 1:267ff9a39ee4 483
yohoo15 1:267ff9a39ee4 484 //pressing va
yohoo15 1:267ff9a39ee4 485 directionPin_key.write(cw);
yohoo15 1:267ff9a39ee4 486 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 487 wait(0.14); //time it takes pwm of one to reach the key
yohoo15 1:267ff9a39ee4 488 //pause at the key for one second
yohoo15 1:267ff9a39ee4 489 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 490 wait(1);
yohoo15 1:267ff9a39ee4 491 //move bakc to the starting position
yohoo15 1:267ff9a39ee4 492 directionPin_key.write(ccw);
yohoo15 1:267ff9a39ee4 493 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 494 //time needs to be slightly longer than moving forward (no answer why)
yohoo15 1:267ff9a39ee4 495 wait(0.165f);
yohoo15 1:267ff9a39ee4 496 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 497
yohoo15 1:267ff9a39ee4 498 // go 1 key to right
yohoo15 1:267ff9a39ee4 499 directionPin.write(cw);
yohoo15 1:267ff9a39ee4 500 PWM.write(1);
yohoo15 1:267ff9a39ee4 501 wait(2.2);
yohoo15 1:267ff9a39ee4 502 PWM.write(0);
yohoo15 1:267ff9a39ee4 503
yohoo15 1:267ff9a39ee4 504 //pressing der
yohoo15 1:267ff9a39ee4 505 directionPin_key.write(cw);
yohoo15 1:267ff9a39ee4 506 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 507 wait(0.14); //time it takes pwm of one to reach the key
yohoo15 1:267ff9a39ee4 508 //pause at the key for one second
yohoo15 1:267ff9a39ee4 509 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 510 wait(1);
yohoo15 1:267ff9a39ee4 511 //move bakc to the starting position
yohoo15 1:267ff9a39ee4 512 directionPin_key.write(ccw);
yohoo15 1:267ff9a39ee4 513 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 514 //time needs to be slightly longer than moving forward (no answer why)
yohoo15 1:267ff9a39ee4 515 wait(0.165f);
yohoo15 1:267ff9a39ee4 516 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 517
yohoo15 1:267ff9a39ee4 518 // go 1 key to right
yohoo15 1:267ff9a39ee4 519 directionPin.write(cw);
yohoo15 1:267ff9a39ee4 520 PWM.write(1);
yohoo15 1:267ff9a39ee4 521 wait(2.2);
yohoo15 1:267ff9a39ee4 522 PWM.write(0);
yohoo15 1:267ff9a39ee4 523
yohoo15 1:267ff9a39ee4 524 //pressing ja
yohoo15 1:267ff9a39ee4 525 directionPin_key.write(cw);
yohoo15 1:267ff9a39ee4 526 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 527 wait(0.14); //time it takes pwm of one to reach the key
yohoo15 1:267ff9a39ee4 528 //pause at the key for one second
yohoo15 1:267ff9a39ee4 529 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 530 wait(1);
yohoo15 1:267ff9a39ee4 531 //move bakc to the starting position
yohoo15 1:267ff9a39ee4 532 directionPin_key.write(ccw);
yohoo15 1:267ff9a39ee4 533 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 534 //time needs to be slightly longer than moving forward (no answer why)
yohoo15 1:267ff9a39ee4 535 wait(0.165f);
yohoo15 1:267ff9a39ee4 536 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 537
yohoo15 1:267ff9a39ee4 538 // go 2 key to left
yohoo15 1:267ff9a39ee4 539 directionPin.write(ccw);
yohoo15 1:267ff9a39ee4 540 PWM.write(1);
yohoo15 1:267ff9a39ee4 541 wait(4.5);
yohoo15 1:267ff9a39ee4 542 PWM.write(0);
yohoo15 1:267ff9a39ee4 543
yohoo15 1:267ff9a39ee4 544 //pressing cob
yohoo15 1:267ff9a39ee4 545 directionPin_key.write(cw);
yohoo15 1:267ff9a39ee4 546 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 547 wait(0.14); //time it takes pwm of one to reach the key
yohoo15 1:267ff9a39ee4 548 //pause at the key for one second
yohoo15 1:267ff9a39ee4 549 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 550 wait(1);
yohoo15 1:267ff9a39ee4 551 //move bakc to the starting position
yohoo15 1:267ff9a39ee4 552 directionPin_key.write(ccw);
yohoo15 1:267ff9a39ee4 553 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 554 //time needs to be slightly longer than moving forward (no answer why)
yohoo15 1:267ff9a39ee4 555 wait(0.165f);
yohoo15 1:267ff9a39ee4 556 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 557
yohoo15 1:267ff9a39ee4 558 wait(1);
yohoo15 1:267ff9a39ee4 559
yohoo15 1:267ff9a39ee4 560 //pressing va
yohoo15 1:267ff9a39ee4 561 directionPin_key.write(cw);
yohoo15 1:267ff9a39ee4 562 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 563 wait(0.14); //time it takes pwm of one to reach the key
yohoo15 1:267ff9a39ee4 564 //pause at the key for one second
yohoo15 1:267ff9a39ee4 565 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 566 wait(1);
yohoo15 1:267ff9a39ee4 567 //move bakc to the starting position
yohoo15 1:267ff9a39ee4 568 directionPin_key.write(ccw);
yohoo15 1:267ff9a39ee4 569 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 570 //time needs to be slightly longer than moving forward (no answer why)
yohoo15 1:267ff9a39ee4 571 wait(0.165f);
yohoo15 1:267ff9a39ee4 572 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 573
yohoo15 1:267ff9a39ee4 574 // go 1 key to right
yohoo15 1:267ff9a39ee4 575 directionPin.write(cw);
yohoo15 1:267ff9a39ee4 576 PWM.write(1);
yohoo15 1:267ff9a39ee4 577 wait(2.2);
yohoo15 1:267ff9a39ee4 578 PWM.write(0);
yohoo15 1:267ff9a39ee4 579
yohoo15 1:267ff9a39ee4 580 //pressing der
yohoo15 1:267ff9a39ee4 581 directionPin_key.write(cw);
yohoo15 1:267ff9a39ee4 582 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 583 wait(0.14); //time it takes pwm of one to reach the key
yohoo15 1:267ff9a39ee4 584 //pause at the key for one second
yohoo15 1:267ff9a39ee4 585 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 586 wait(1);
yohoo15 1:267ff9a39ee4 587 //move bakc to the starting position
yohoo15 1:267ff9a39ee4 588 directionPin_key.write(ccw);
yohoo15 1:267ff9a39ee4 589 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 590 //time needs to be slightly longer than moving forward (no answer why)
yohoo15 1:267ff9a39ee4 591 wait(0.165f);
yohoo15 1:267ff9a39ee4 592 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 593
yohoo15 1:267ff9a39ee4 594 // go 1 key to right
yohoo15 1:267ff9a39ee4 595 directionPin.write(cw);
yohoo15 1:267ff9a39ee4 596 PWM.write(1);
yohoo15 1:267ff9a39ee4 597 wait(2.2);
yohoo15 1:267ff9a39ee4 598 PWM.write(0);
yohoo15 1:267ff9a39ee4 599
yohoo15 1:267ff9a39ee4 600 //pressing ja
yohoo15 1:267ff9a39ee4 601 directionPin_key.write(cw);
yohoo15 1:267ff9a39ee4 602 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 603 wait(0.14); //time it takes pwm of one to reach the key
yohoo15 1:267ff9a39ee4 604 //pause at the key for one second
yohoo15 1:267ff9a39ee4 605 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 606 wait(1);
yohoo15 1:267ff9a39ee4 607 //move bakc to the starting position
yohoo15 1:267ff9a39ee4 608 directionPin_key.write(ccw);
yohoo15 1:267ff9a39ee4 609 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 610 //time needs to be slightly longer than moving forward (no answer why)
yohoo15 1:267ff9a39ee4 611 wait(0.165f);
yohoo15 1:267ff9a39ee4 612 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 613
yohoo15 1:267ff9a39ee4 614 // go 2 key to left
yohoo15 1:267ff9a39ee4 615 directionPin.write(ccw);
yohoo15 1:267ff9a39ee4 616 PWM.write(1);
yohoo15 1:267ff9a39ee4 617 wait(4.5);
yohoo15 1:267ff9a39ee4 618 PWM.write(0);
yohoo15 1:267ff9a39ee4 619
yohoo15 1:267ff9a39ee4 620 //pressing cob
yohoo15 1:267ff9a39ee4 621 directionPin_key.write(cw);
yohoo15 1:267ff9a39ee4 622 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 623 wait(0.14); //time it takes pwm of one to reach the key
yohoo15 1:267ff9a39ee4 624 //pause at the key for one second
yohoo15 1:267ff9a39ee4 625 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 626 wait(1);
yohoo15 1:267ff9a39ee4 627 //move bakc to the starting position
yohoo15 1:267ff9a39ee4 628 directionPin_key.write(ccw);
yohoo15 1:267ff9a39ee4 629 PWM_key.write(1);
yohoo15 1:267ff9a39ee4 630 //time needs to be slightly longer than moving forward (no answer why)
yohoo15 1:267ff9a39ee4 631 wait(0.165f);
yohoo15 1:267ff9a39ee4 632 PWM_key.write(0);
yohoo15 1:267ff9a39ee4 633 }
yohoo15 0:0f08f98ae7f8 634 }
yohoo15 0:0f08f98ae7f8 635 }
yohoo15 0:0f08f98ae7f8 636