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