Makoto Kobayashi
/
Kikaikougaku_Jikken_mecolab
機械工学実験1
main.cpp@0:41033932c9ec, 2014-10-20 (annotated)
- Committer:
- neoqased
- Date:
- Mon Oct 20 11:30:35 2014 +0000
- Revision:
- 0:41033932c9ec
- Child:
- 1:35d14e37db1b
??????1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
neoqased | 0:41033932c9ec | 1 | //include header file |
neoqased | 0:41033932c9ec | 2 | #include "mbed.h" |
neoqased | 0:41033932c9ec | 3 | #include "QEI.h" |
neoqased | 0:41033932c9ec | 4 | #include "PID.h" |
neoqased | 0:41033932c9ec | 5 | #include "setting.h" |
neoqased | 0:41033932c9ec | 6 | |
neoqased | 0:41033932c9ec | 7 | //define |
neoqased | 0:41033932c9ec | 8 | #define PULSE_PER_REVOLUTION 200 |
neoqased | 0:41033932c9ec | 9 | #define PID_RATE 10 //wait **ms |
neoqased | 0:41033932c9ec | 10 | |
neoqased | 0:41033932c9ec | 11 | //IO pin setting |
neoqased | 0:41033932c9ec | 12 | DigitalOut led1(LED1); //mbed LED outputs |
neoqased | 0:41033932c9ec | 13 | DigitalOut led2(LED2); |
neoqased | 0:41033932c9ec | 14 | DigitalOut led3(LED3); |
neoqased | 0:41033932c9ec | 15 | DigitalOut led4(LED4); |
neoqased | 0:41033932c9ec | 16 | DigitalIn dip1(p5); //DIP switch inputs |
neoqased | 0:41033932c9ec | 17 | DigitalIn dip2(p6); |
neoqased | 0:41033932c9ec | 18 | DigitalIn dip3(p7); |
neoqased | 0:41033932c9ec | 19 | DigitalIn dip4(p8); |
neoqased | 0:41033932c9ec | 20 | DigitalIn startsw(p9); //push switch input |
neoqased | 0:41033932c9ec | 21 | DigitalOut buzzer(p18); //buzzer output |
neoqased | 0:41033932c9ec | 22 | AnalogIn volume(p20); //potentiometer input |
neoqased | 0:41033932c9ec | 23 | PwmOut pwm(p25); //pwm output to a motordriver |
neoqased | 0:41033932c9ec | 24 | |
neoqased | 0:41033932c9ec | 25 | //other setting |
neoqased | 0:41033932c9ec | 26 | Serial pc(USBTX, USBRX); //set serial communication with PC |
neoqased | 0:41033932c9ec | 27 | QEI encoder(p30, p29, NC, PULSE_PER_REVOLUTION, QEI::X2_ENCODING); //QEI setting (See QEI.cpp) |
neoqased | 0:41033932c9ec | 28 | Timer timer; //mbed timer setting (See mbed description) |
neoqased | 0:41033932c9ec | 29 | |
neoqased | 0:41033932c9ec | 30 | //structure of experimentation result |
neoqased | 0:41033932c9ec | 31 | typedef struct{ |
neoqased | 0:41033932c9ec | 32 | float t; |
neoqased | 0:41033932c9ec | 33 | float rpm; |
neoqased | 0:41033932c9ec | 34 | } result; |
neoqased | 0:41033932c9ec | 35 | |
neoqased | 0:41033932c9ec | 36 | //prototype declaration |
neoqased | 0:41033932c9ec | 37 | int Init(); |
neoqased | 0:41033932c9ec | 38 | int DipLed(); |
neoqased | 0:41033932c9ec | 39 | int GetDipValue(); |
neoqased | 0:41033932c9ec | 40 | int SW(); |
neoqased | 0:41033932c9ec | 41 | int Buzzer(int buzvar); |
neoqased | 0:41033932c9ec | 42 | |
neoqased | 0:41033932c9ec | 43 | //main function |
neoqased | 0:41033932c9ec | 44 | int main() { |
neoqased | 0:41033932c9ec | 45 | Buzzer(2); //ring buzzer after pushing a reset button |
neoqased | 0:41033932c9ec | 46 | LocalFileSystem local("local"); //set mbed root directory as "local" |
neoqased | 0:41033932c9ec | 47 | Init(); //initialize |
neoqased | 0:41033932c9ec | 48 | int flag = 0; //variable of operation mode |
neoqased | 0:41033932c9ec | 49 | result exp[(int)(15*1000/PID_RATE+1)] = {}; //variable for experimentation result |
neoqased | 0:41033932c9ec | 50 | |
neoqased | 0:41033932c9ec | 51 | while(1){ //main loop |
neoqased | 0:41033932c9ec | 52 | Init(); //initialize |
neoqased | 0:41033932c9ec | 53 | for(int i = 0; i <= 15*1000/PID_RATE; i++){ //initialize result structure |
neoqased | 0:41033932c9ec | 54 | exp[i].t = 0; |
neoqased | 0:41033932c9ec | 55 | exp[i].rpm = 0; |
neoqased | 0:41033932c9ec | 56 | } |
neoqased | 0:41033932c9ec | 57 | SW(); //wait for startswitch push |
neoqased | 0:41033932c9ec | 58 | flag = GetDipValue(); //read DIP switch value |
neoqased | 0:41033932c9ec | 59 | DipLed(); //make mbed LED shine |
neoqased | 0:41033932c9ec | 60 | Buzzer(1); //ring buzzer mode 1 |
neoqased | 0:41033932c9ec | 61 | |
neoqased | 0:41033932c9ec | 62 | switch (flag){ |
neoqased | 0:41033932c9ec | 63 | /*********************mode 0**********************/ |
neoqased | 0:41033932c9ec | 64 | case 0: //mode 0: nothing |
neoqased | 0:41033932c9ec | 65 | break; |
neoqased | 0:41033932c9ec | 66 | /*********************mode 1**********************/ |
neoqased | 0:41033932c9ec | 67 | case 1:{ //mode 1: manually operated mode |
neoqased | 0:41033932c9ec | 68 | float vol = 0; //variable of potentiometer |
neoqased | 0:41033932c9ec | 69 | float rpm = 0; //variable of rpm |
neoqased | 0:41033932c9ec | 70 | float t = 0; //variable of time |
neoqased | 0:41033932c9ec | 71 | int i1 = 0; //variable of loop count |
neoqased | 0:41033932c9ec | 72 | encoder.reset(); |
neoqased | 0:41033932c9ec | 73 | timer.reset(); |
neoqased | 0:41033932c9ec | 74 | timer.start(); |
neoqased | 0:41033932c9ec | 75 | while(1){ |
neoqased | 0:41033932c9ec | 76 | vol = 1 - volume; //min position(max input(H))<-----potentiometer=====>(min input(L))max position |
neoqased | 0:41033932c9ec | 77 | pwm = vol; |
neoqased | 0:41033932c9ec | 78 | if(i1 >= 20){ //show duty ratio and rpm in PC every sec |
neoqased | 0:41033932c9ec | 79 | t = timer.read(); |
neoqased | 0:41033932c9ec | 80 | rpm = (float)encoder.getPulses() / 2 / PULSE_PER_REVOLUTION * 60 / t * 2; //reduction ratio 1/2 |
neoqased | 0:41033932c9ec | 81 | pc.printf("Duty Ratio = %.3f , %6d RPM\n", vol, (int)rpm); |
neoqased | 0:41033932c9ec | 82 | encoder.reset(); |
neoqased | 0:41033932c9ec | 83 | i1 = 0; |
neoqased | 0:41033932c9ec | 84 | timer.reset(); |
neoqased | 0:41033932c9ec | 85 | } |
neoqased | 0:41033932c9ec | 86 | wait_ms(50); |
neoqased | 0:41033932c9ec | 87 | i1++; |
neoqased | 0:41033932c9ec | 88 | } |
neoqased | 0:41033932c9ec | 89 | break; |
neoqased | 0:41033932c9ec | 90 | } |
neoqased | 0:41033932c9ec | 91 | /*********************mode 2**********************/ |
neoqased | 0:41033932c9ec | 92 | case 2:{ //mode 2: step input |
neoqased | 0:41033932c9ec | 93 | exp[0].t = 0; |
neoqased | 0:41033932c9ec | 94 | exp[0].rpm = 0; |
neoqased | 0:41033932c9ec | 95 | encoder.reset(); |
neoqased | 0:41033932c9ec | 96 | timer.reset(); |
neoqased | 0:41033932c9ec | 97 | timer.start(); |
neoqased | 0:41033932c9ec | 98 | pwm = 1; //duty ratio 1 |
neoqased | 0:41033932c9ec | 99 | for(int i = 0; i < 15*1000/PID_RATE; i++){ //variable assignment in every PID_RATE |
neoqased | 0:41033932c9ec | 100 | wait_ms(PID_RATE); |
neoqased | 0:41033932c9ec | 101 | exp[i+1].t = timer.read(); |
neoqased | 0:41033932c9ec | 102 | exp[i+1].rpm = (float)encoder.getPulses() / 2 / PULSE_PER_REVOLUTION * 60 / (exp[i+1].t - exp[i].t) * 2; |
neoqased | 0:41033932c9ec | 103 | encoder.reset(); |
neoqased | 0:41033932c9ec | 104 | } |
neoqased | 0:41033932c9ec | 105 | for(int i = 100; i >= 0; i--){ //stopping motor slowly |
neoqased | 0:41033932c9ec | 106 | pwm = (float)i / 100; |
neoqased | 0:41033932c9ec | 107 | wait_ms(20); |
neoqased | 0:41033932c9ec | 108 | } |
neoqased | 0:41033932c9ec | 109 | pwm = 0; |
neoqased | 0:41033932c9ec | 110 | wait(1); |
neoqased | 0:41033932c9ec | 111 | FILE * fp = fopen("/local/exp2.csv","w"); |
neoqased | 0:41033932c9ec | 112 | if(fp == NULL){ |
neoqased | 0:41033932c9ec | 113 | Buzzer(-1); |
neoqased | 0:41033932c9ec | 114 | break; |
neoqased | 0:41033932c9ec | 115 | } |
neoqased | 0:41033932c9ec | 116 | fprintf(fp,"Time , RPM\n"); |
neoqased | 0:41033932c9ec | 117 | for(int i = 0; i <= 15*1000/PID_RATE; i++){ //output results |
neoqased | 0:41033932c9ec | 118 | fprintf(fp,"%f , %f\n", exp[i].t, exp[i].rpm); |
neoqased | 0:41033932c9ec | 119 | } |
neoqased | 0:41033932c9ec | 120 | fclose(fp); |
neoqased | 0:41033932c9ec | 121 | Buzzer(4); //ring finish buzzer |
neoqased | 0:41033932c9ec | 122 | break; |
neoqased | 0:41033932c9ec | 123 | } |
neoqased | 0:41033932c9ec | 124 | /*********************mode 3**********************/ |
neoqased | 0:41033932c9ec | 125 | case 3:{ //mode 3: PID control |
neoqased | 0:41033932c9ec | 126 | float kp = 0, ti = 0, td = 0, max_rpm = 0, target_rpm = 0, reduction = 0; |
neoqased | 0:41033932c9ec | 127 | encoder.reset(); |
neoqased | 0:41033932c9ec | 128 | timer.reset(); |
neoqased | 0:41033932c9ec | 129 | |
neoqased | 0:41033932c9ec | 130 | kp = KP; //substitute from setting.h |
neoqased | 0:41033932c9ec | 131 | ti = TI; |
neoqased | 0:41033932c9ec | 132 | td = TD; |
neoqased | 0:41033932c9ec | 133 | max_rpm = MAX_RPM; |
neoqased | 0:41033932c9ec | 134 | target_rpm = TARGET_RPM; |
neoqased | 0:41033932c9ec | 135 | |
neoqased | 0:41033932c9ec | 136 | PID pid(kp, ti, td, PID_RATE); //PID setting (see PID.cpp) |
neoqased | 0:41033932c9ec | 137 | pid.setInputLimits(0.0, max_rpm); |
neoqased | 0:41033932c9ec | 138 | pid.setOutputLimits(0.0, 1.0); |
neoqased | 0:41033932c9ec | 139 | pid.setMode(AUTO_MODE); |
neoqased | 0:41033932c9ec | 140 | pid.setSetPoint(target_rpm); |
neoqased | 0:41033932c9ec | 141 | |
neoqased | 0:41033932c9ec | 142 | exp[0].t = 0; |
neoqased | 0:41033932c9ec | 143 | exp[0].rpm = 0; |
neoqased | 0:41033932c9ec | 144 | timer.start(); //count start |
neoqased | 0:41033932c9ec | 145 | for(int i = 0; i < 15*1000/PID_RATE; i++){ //PID control loop(15 seconds) |
neoqased | 0:41033932c9ec | 146 | exp[i+1].t = timer.read(); |
neoqased | 0:41033932c9ec | 147 | exp[i+1].rpm = (float)encoder.getPulses() / 2 / PULSE_PER_REVOLUTION * 60 / (exp[i+1].t - exp[i].t) * 2; |
neoqased | 0:41033932c9ec | 148 | pid.setProcessValue(exp[i+1].rpm); |
neoqased | 0:41033932c9ec | 149 | pwm = pid.compute(); |
neoqased | 0:41033932c9ec | 150 | encoder.reset(); |
neoqased | 0:41033932c9ec | 151 | wait_ms(PID_RATE); |
neoqased | 0:41033932c9ec | 152 | } |
neoqased | 0:41033932c9ec | 153 | reduction = pwm.read(); //stopping slowly loop |
neoqased | 0:41033932c9ec | 154 | for(int i = 0; i <= 100; i++){ |
neoqased | 0:41033932c9ec | 155 | pwm = pwm.read() - reduction / 100; |
neoqased | 0:41033932c9ec | 156 | wait_ms(20); |
neoqased | 0:41033932c9ec | 157 | } |
neoqased | 0:41033932c9ec | 158 | pwm = 0; |
neoqased | 0:41033932c9ec | 159 | FILE *fp = fopen("/local/exp3.csv","w"); |
neoqased | 0:41033932c9ec | 160 | if(fp == NULL){ |
neoqased | 0:41033932c9ec | 161 | Buzzer(-1); |
neoqased | 0:41033932c9ec | 162 | break; |
neoqased | 0:41033932c9ec | 163 | } |
neoqased | 0:41033932c9ec | 164 | fprintf(fp,", kp = %f ki = %f kd = %f\n",kp, ti, td); |
neoqased | 0:41033932c9ec | 165 | fprintf(fp,"Time , RPM\n"); |
neoqased | 0:41033932c9ec | 166 | for(int i = 0; i <= 15*1000/PID_RATE; i++){ //output results |
neoqased | 0:41033932c9ec | 167 | fprintf(fp,"%f , %f\n", exp[i].t, exp[i].rpm); |
neoqased | 0:41033932c9ec | 168 | } |
neoqased | 0:41033932c9ec | 169 | fclose(fp); |
neoqased | 0:41033932c9ec | 170 | Buzzer(5); //ring finish buzzer |
neoqased | 0:41033932c9ec | 171 | break; |
neoqased | 0:41033932c9ec | 172 | } |
neoqased | 0:41033932c9ec | 173 | /*********************default**********************/ |
neoqased | 0:41033932c9ec | 174 | default: |
neoqased | 0:41033932c9ec | 175 | break; |
neoqased | 0:41033932c9ec | 176 | } |
neoqased | 0:41033932c9ec | 177 | } |
neoqased | 0:41033932c9ec | 178 | } |
neoqased | 0:41033932c9ec | 179 | |
neoqased | 0:41033932c9ec | 180 | int Init(){ //initialize function |
neoqased | 0:41033932c9ec | 181 | pwm = 0; |
neoqased | 0:41033932c9ec | 182 | led1 = 0; |
neoqased | 0:41033932c9ec | 183 | led2 = 0; |
neoqased | 0:41033932c9ec | 184 | led3 = 0; |
neoqased | 0:41033932c9ec | 185 | led4 = 0; |
neoqased | 0:41033932c9ec | 186 | buzzer = 0; |
neoqased | 0:41033932c9ec | 187 | pc.baud(9600); |
neoqased | 0:41033932c9ec | 188 | encoder.reset(); |
neoqased | 0:41033932c9ec | 189 | timer.reset(); |
neoqased | 0:41033932c9ec | 190 | pwm.period_us(25); |
neoqased | 0:41033932c9ec | 191 | DipLed(); |
neoqased | 0:41033932c9ec | 192 | return 0; |
neoqased | 0:41033932c9ec | 193 | } |
neoqased | 0:41033932c9ec | 194 | |
neoqased | 0:41033932c9ec | 195 | int DipLed(){ //LED flash function |
neoqased | 0:41033932c9ec | 196 | if(dip1 == 1) led1 = 1; else led1 = 0; |
neoqased | 0:41033932c9ec | 197 | if(dip2 == 1) led2 = 1; else led2 = 0; |
neoqased | 0:41033932c9ec | 198 | if(dip3 == 1) led3 = 1; else led3 = 0; |
neoqased | 0:41033932c9ec | 199 | if(dip4 == 1) led4 = 1; else led4 = 0; |
neoqased | 0:41033932c9ec | 200 | return 0; |
neoqased | 0:41033932c9ec | 201 | } |
neoqased | 0:41033932c9ec | 202 | |
neoqased | 0:41033932c9ec | 203 | int GetDipValue(){ //DIP switch function |
neoqased | 0:41033932c9ec | 204 | int Dip1 = dip1, Dip2 = dip2, Dip3 = dip3, Dip4 = dip4; |
neoqased | 0:41033932c9ec | 205 | if(Dip1 == 0){ |
neoqased | 0:41033932c9ec | 206 | if(Dip2 == 0){ |
neoqased | 0:41033932c9ec | 207 | if(Dip3 == 0){ |
neoqased | 0:41033932c9ec | 208 | if(Dip4 == 0) return 0; else return 1; |
neoqased | 0:41033932c9ec | 209 | }else{ |
neoqased | 0:41033932c9ec | 210 | if(Dip4 == 0) return 2; else return 3; |
neoqased | 0:41033932c9ec | 211 | } |
neoqased | 0:41033932c9ec | 212 | }else{ |
neoqased | 0:41033932c9ec | 213 | if(Dip3 == 0){ |
neoqased | 0:41033932c9ec | 214 | if(Dip4 == 0) return 4; else return 5; |
neoqased | 0:41033932c9ec | 215 | }else{ |
neoqased | 0:41033932c9ec | 216 | if(Dip4 == 0) return 6; else return 7; |
neoqased | 0:41033932c9ec | 217 | } |
neoqased | 0:41033932c9ec | 218 | } |
neoqased | 0:41033932c9ec | 219 | }else{ |
neoqased | 0:41033932c9ec | 220 | if(Dip2 == 0){ |
neoqased | 0:41033932c9ec | 221 | if(Dip3 == 0){ |
neoqased | 0:41033932c9ec | 222 | if(Dip4 == 0) return 8; else return 9; |
neoqased | 0:41033932c9ec | 223 | }else{ |
neoqased | 0:41033932c9ec | 224 | if(Dip4 == 0) return 10; else return 11; |
neoqased | 0:41033932c9ec | 225 | } |
neoqased | 0:41033932c9ec | 226 | }else{ |
neoqased | 0:41033932c9ec | 227 | if(Dip3 == 0){ |
neoqased | 0:41033932c9ec | 228 | if(Dip4 == 0) return 12; else return 13; |
neoqased | 0:41033932c9ec | 229 | }else{ |
neoqased | 0:41033932c9ec | 230 | if(Dip4 == 0) return 14; else return 15; |
neoqased | 0:41033932c9ec | 231 | } |
neoqased | 0:41033932c9ec | 232 | } |
neoqased | 0:41033932c9ec | 233 | } |
neoqased | 0:41033932c9ec | 234 | } |
neoqased | 0:41033932c9ec | 235 | |
neoqased | 0:41033932c9ec | 236 | int SW(){ //startswitch function |
neoqased | 0:41033932c9ec | 237 | int i = 0, j = 0; |
neoqased | 0:41033932c9ec | 238 | while(i < 3){ |
neoqased | 0:41033932c9ec | 239 | if(startsw == 1) i++; |
neoqased | 0:41033932c9ec | 240 | else i = 0; |
neoqased | 0:41033932c9ec | 241 | DipLed(); |
neoqased | 0:41033932c9ec | 242 | wait_ms(5); |
neoqased | 0:41033932c9ec | 243 | } |
neoqased | 0:41033932c9ec | 244 | while(j < 3){ |
neoqased | 0:41033932c9ec | 245 | if(startsw == 0) j++; |
neoqased | 0:41033932c9ec | 246 | else j = 0; |
neoqased | 0:41033932c9ec | 247 | DipLed(); |
neoqased | 0:41033932c9ec | 248 | wait_ms(5); |
neoqased | 0:41033932c9ec | 249 | } |
neoqased | 0:41033932c9ec | 250 | return 0; |
neoqased | 0:41033932c9ec | 251 | } |
neoqased | 0:41033932c9ec | 252 | |
neoqased | 0:41033932c9ec | 253 | int Buzzer(int buzvar){ //ringing buzzer function |
neoqased | 0:41033932c9ec | 254 | switch (buzvar){ |
neoqased | 0:41033932c9ec | 255 | case -3: //error * - - |
neoqased | 0:41033932c9ec | 256 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 257 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.3); |
neoqased | 0:41033932c9ec | 258 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.3); |
neoqased | 0:41033932c9ec | 259 | break; |
neoqased | 0:41033932c9ec | 260 | case -2: //error * - - - |
neoqased | 0:41033932c9ec | 261 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 262 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.3); |
neoqased | 0:41033932c9ec | 263 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.3); |
neoqased | 0:41033932c9ec | 264 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.3); |
neoqased | 0:41033932c9ec | 265 | break; |
neoqased | 0:41033932c9ec | 266 | case -1: //error * - - - - |
neoqased | 0:41033932c9ec | 267 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 268 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.3); |
neoqased | 0:41033932c9ec | 269 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.3); |
neoqased | 0:41033932c9ec | 270 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.3); |
neoqased | 0:41033932c9ec | 271 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.3); |
neoqased | 0:41033932c9ec | 272 | break; |
neoqased | 0:41033932c9ec | 273 | case 0: //no sound |
neoqased | 0:41033932c9ec | 274 | buzzer = 0; |
neoqased | 0:41033932c9ec | 275 | break; |
neoqased | 0:41033932c9ec | 276 | case 1: //* |
neoqased | 0:41033932c9ec | 277 | buzzer = 1; wait(0.1); buzzer = 0; |
neoqased | 0:41033932c9ec | 278 | break; |
neoqased | 0:41033932c9ec | 279 | case 2: //* * |
neoqased | 0:41033932c9ec | 280 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.05); |
neoqased | 0:41033932c9ec | 281 | buzzer = 1; wait(0.1); buzzer = 0; |
neoqased | 0:41033932c9ec | 282 | break; |
neoqased | 0:41033932c9ec | 283 | case 3: //- |
neoqased | 0:41033932c9ec | 284 | buzzer = 1; wait(0.3); buzzer = 0; |
neoqased | 0:41033932c9ec | 285 | break; |
neoqased | 0:41033932c9ec | 286 | case 4: //- - |
neoqased | 0:41033932c9ec | 287 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.3); |
neoqased | 0:41033932c9ec | 288 | buzzer = 1; wait(0.3); buzzer = 0; |
neoqased | 0:41033932c9ec | 289 | break; |
neoqased | 0:41033932c9ec | 290 | case 5: //--- |
neoqased | 0:41033932c9ec | 291 | buzzer = 1; wait(0.9); buzzer = 0; |
neoqased | 0:41033932c9ec | 292 | break; |
neoqased | 0:41033932c9ec | 293 | case 6: //* * * * * * * * * * |
neoqased | 0:41033932c9ec | 294 | for(int i = 0; i < 3; i++){ |
neoqased | 0:41033932c9ec | 295 | for(int j = 0; j < 3; j++){ |
neoqased | 0:41033932c9ec | 296 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 297 | } |
neoqased | 0:41033932c9ec | 298 | wait(0.2); |
neoqased | 0:41033932c9ec | 299 | } |
neoqased | 0:41033932c9ec | 300 | buzzer = 1; wait(0.1); buzzer = 0; |
neoqased | 0:41033932c9ec | 301 | break; |
neoqased | 0:41033932c9ec | 302 | case 7: // **-* ** -* ** *** **** |
neoqased | 0:41033932c9ec | 303 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 304 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 305 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 306 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 307 | wait(0.2); |
neoqased | 0:41033932c9ec | 308 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 309 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 310 | wait(0.2); |
neoqased | 0:41033932c9ec | 311 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 312 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 313 | wait(0.2); |
neoqased | 0:41033932c9ec | 314 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 315 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 316 | wait(0.2); |
neoqased | 0:41033932c9ec | 317 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 318 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 319 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 320 | wait(0.2); |
neoqased | 0:41033932c9ec | 321 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 322 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 323 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 324 | buzzer = 1; wait(0.1); buzzer = 0; |
neoqased | 0:41033932c9ec | 325 | break; |
neoqased | 0:41033932c9ec | 326 | case 8: // *-*** -*- --* |
neoqased | 0:41033932c9ec | 327 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 328 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 329 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 330 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 331 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 332 | wait(0.2); |
neoqased | 0:41033932c9ec | 333 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 334 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 335 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 336 | wait(0.2); |
neoqased | 0:41033932c9ec | 337 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 338 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.1); |
neoqased | 0:41033932c9ec | 339 | buzzer = 1; wait(0.1); buzzer = 0; |
neoqased | 0:41033932c9ec | 340 | break; |
neoqased | 0:41033932c9ec | 341 | default: //no sound |
neoqased | 0:41033932c9ec | 342 | buzzer = 0; |
neoqased | 0:41033932c9ec | 343 | break; |
neoqased | 0:41033932c9ec | 344 | } |
neoqased | 0:41033932c9ec | 345 | return 0; |
neoqased | 0:41033932c9ec | 346 | } |