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