fina mbed source

Dependencies:   mbed TCS3472_I2C VL6180

Committer:
xinzhizhulaoban
Date:
Mon Dec 17 04:53:52 2018 +0000
Revision:
0:22fc25c6238e
MBED source

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xinzhizhulaoban 0:22fc25c6238e 1 #include "mbed.h"
xinzhizhulaoban 0:22fc25c6238e 2 #include "TCS3472_I2C.h"
xinzhizhulaoban 0:22fc25c6238e 3 #include "VL6180.h"
xinzhizhulaoban 0:22fc25c6238e 4 DigitalOut distance_over(p24);
xinzhizhulaoban 0:22fc25c6238e 5 DigitalOut start_Digital_Tube(p15);
xinzhizhulaoban 0:22fc25c6238e 6 DigitalOut start_LED(p16);
xinzhizhulaoban 0:22fc25c6238e 7 DigitalOut start_question1(p18);
xinzhizhulaoban 0:22fc25c6238e 8 DigitalOut start_question2(p19);
xinzhizhulaoban 0:22fc25c6238e 9 DigitalIn result1_led(p7);
xinzhizhulaoban 0:22fc25c6238e 10 DigitalIn result2_led(p8);
xinzhizhulaoban 0:22fc25c6238e 11 DigitalIn result1_Digital_Tube(p11);
xinzhizhulaoban 0:22fc25c6238e 12 DigitalIn result2_Digital_Tube(p12);
xinzhizhulaoban 0:22fc25c6238e 13 DigitalIn result1_question(p13);
xinzhizhulaoban 0:22fc25c6238e 14 DigitalIn result2_question(p14);
xinzhizhulaoban 0:22fc25c6238e 15 VL6180 TOF_sensor(p28, p27);
xinzhizhulaoban 0:22fc25c6238e 16 TCS3472_I2C rgb_sensor(p9, p10);
xinzhizhulaoban 0:22fc25c6238e 17 DigitalOut color1(p21);
xinzhizhulaoban 0:22fc25c6238e 18 DigitalOut color2(p22);
xinzhizhulaoban 0:22fc25c6238e 19 DigitalOut start_good_supply(p17);
xinzhizhulaoban 0:22fc25c6238e 20 DigitalIn color_over(p23);
xinzhizhulaoban 0:22fc25c6238e 21 DigitalOut servo_test(p20);
xinzhizhulaoban 0:22fc25c6238e 22 DigitalIn infrared1(p25);
xinzhizhulaoban 0:22fc25c6238e 23 DigitalIn infrared3(p26);
xinzhizhulaoban 0:22fc25c6238e 24 DigitalIn infrared2(p29);
xinzhizhulaoban 0:22fc25c6238e 25 DigitalIn infrared4(p30);
xinzhizhulaoban 0:22fc25c6238e 26
xinzhizhulaoban 0:22fc25c6238e 27
xinzhizhulaoban 0:22fc25c6238e 28 Serial pc(USBTX, USBRX);
xinzhizhulaoban 0:22fc25c6238e 29
xinzhizhulaoban 0:22fc25c6238e 30 int main()
xinzhizhulaoban 0:22fc25c6238e 31 {
xinzhizhulaoban 0:22fc25c6238e 32 int game_count;
xinzhizhulaoban 0:22fc25c6238e 33 int distance_count;
xinzhizhulaoban 0:22fc25c6238e 34 int good_shut_down;
xinzhizhulaoban 0:22fc25c6238e 35 int Digital_Tube,LED,QUESTION1,QUESTION2;
xinzhizhulaoban 0:22fc25c6238e 36 uint8_t dist; //distance
xinzhizhulaoban 0:22fc25c6238e 37 int count_color;
xinzhizhulaoban 0:22fc25c6238e 38 char a;
xinzhizhulaoban 0:22fc25c6238e 39 float R,G,B;
xinzhizhulaoban 0:22fc25c6238e 40 TOF_sensor.VL6180_Init();
xinzhizhulaoban 0:22fc25c6238e 41 int rgb_readings[4]; //color
xinzhizhulaoban 0:22fc25c6238e 42 int user,maintance;
xinzhizhulaoban 0:22fc25c6238e 43 rgb_sensor.enablePowerAndRGBC();
xinzhizhulaoban 0:22fc25c6238e 44 rgb_sensor.setIntegrationTime(100);
xinzhizhulaoban 0:22fc25c6238e 45 while(1)
xinzhizhulaoban 0:22fc25c6238e 46 {
xinzhizhulaoban 0:22fc25c6238e 47 Digital_Tube=0;
xinzhizhulaoban 0:22fc25c6238e 48 LED=0;
xinzhizhulaoban 0:22fc25c6238e 49 QUESTION1=0;
xinzhizhulaoban 0:22fc25c6238e 50 QUESTION2=0;
xinzhizhulaoban 0:22fc25c6238e 51 start_Digital_Tube=0;
xinzhizhulaoban 0:22fc25c6238e 52 start_LED=0;
xinzhizhulaoban 0:22fc25c6238e 53 start_question1=0;
xinzhizhulaoban 0:22fc25c6238e 54 start_question2=0;
xinzhizhulaoban 0:22fc25c6238e 55 start_good_supply=0;
xinzhizhulaoban 0:22fc25c6238e 56 servo_test=0;
xinzhizhulaoban 0:22fc25c6238e 57 color1=0;
xinzhizhulaoban 0:22fc25c6238e 58 color2=0;
xinzhizhulaoban 0:22fc25c6238e 59 good_shut_down=0;
xinzhizhulaoban 0:22fc25c6238e 60 distance_over=0;
xinzhizhulaoban 0:22fc25c6238e 61 distance_count=0;
xinzhizhulaoban 0:22fc25c6238e 62 game_count=0;
xinzhizhulaoban 0:22fc25c6238e 63
xinzhizhulaoban 0:22fc25c6238e 64 while(1)
xinzhizhulaoban 0:22fc25c6238e 65 {
xinzhizhulaoban 0:22fc25c6238e 66 a=pc.getc();
xinzhizhulaoban 0:22fc25c6238e 67 if(a=='9')
xinzhizhulaoban 0:22fc25c6238e 68 {
xinzhizhulaoban 0:22fc25c6238e 69 break;
xinzhizhulaoban 0:22fc25c6238e 70 }
xinzhizhulaoban 0:22fc25c6238e 71 }
xinzhizhulaoban 0:22fc25c6238e 72
xinzhizhulaoban 0:22fc25c6238e 73 while(1)
xinzhizhulaoban 0:22fc25c6238e 74 {
xinzhizhulaoban 0:22fc25c6238e 75 dist = TOF_sensor.getDistance(); //always reading the data of distance
xinzhizhulaoban 0:22fc25c6238e 76 if(dist>=100 && dist<255)
xinzhizhulaoban 0:22fc25c6238e 77 {
xinzhizhulaoban 0:22fc25c6238e 78 distance_over=0;
xinzhizhulaoban 0:22fc25c6238e 79 pc.printf("10");
xinzhizhulaoban 0:22fc25c6238e 80 break;
xinzhizhulaoban 0:22fc25c6238e 81 }
xinzhizhulaoban 0:22fc25c6238e 82 else
xinzhizhulaoban 0:22fc25c6238e 83 {
xinzhizhulaoban 0:22fc25c6238e 84 distance_over=1;
xinzhizhulaoban 0:22fc25c6238e 85 }
xinzhizhulaoban 0:22fc25c6238e 86 }
xinzhizhulaoban 0:22fc25c6238e 87 while(1)
xinzhizhulaoban 0:22fc25c6238e 88 {
xinzhizhulaoban 0:22fc25c6238e 89 a=pc.getc();
xinzhizhulaoban 0:22fc25c6238e 90 if(a=='2') //if the mbed get the signal to read card
xinzhizhulaoban 0:22fc25c6238e 91 {
xinzhizhulaoban 0:22fc25c6238e 92 while(1)
xinzhizhulaoban 0:22fc25c6238e 93 {
xinzhizhulaoban 0:22fc25c6238e 94 //identify the card
xinzhizhulaoban 0:22fc25c6238e 95 if(infrared1==1 && infrared2==1 && infrared3==1 && infrared4==1)
xinzhizhulaoban 0:22fc25c6238e 96 {
xinzhizhulaoban 0:22fc25c6238e 97 user=0;
xinzhizhulaoban 0:22fc25c6238e 98 maintance=1;
xinzhizhulaoban 0:22fc25c6238e 99 pc.printf("0");
xinzhizhulaoban 0:22fc25c6238e 100 break;
xinzhizhulaoban 0:22fc25c6238e 101 }
xinzhizhulaoban 0:22fc25c6238e 102 else
xinzhizhulaoban 0:22fc25c6238e 103 {
xinzhizhulaoban 0:22fc25c6238e 104 user=1;
xinzhizhulaoban 0:22fc25c6238e 105 maintance=0;
xinzhizhulaoban 0:22fc25c6238e 106 pc.printf("1");
xinzhizhulaoban 0:22fc25c6238e 107 break;
xinzhizhulaoban 0:22fc25c6238e 108 }
xinzhizhulaoban 0:22fc25c6238e 109 }
xinzhizhulaoban 0:22fc25c6238e 110 break;
xinzhizhulaoban 0:22fc25c6238e 111 }
xinzhizhulaoban 0:22fc25c6238e 112 if(a=='7')
xinzhizhulaoban 0:22fc25c6238e 113 {
xinzhizhulaoban 0:22fc25c6238e 114 break;
xinzhizhulaoban 0:22fc25c6238e 115 }
xinzhizhulaoban 0:22fc25c6238e 116 }
xinzhizhulaoban 0:22fc25c6238e 117 while(user==1 && maintance==0)
xinzhizhulaoban 0:22fc25c6238e 118 {
xinzhizhulaoban 0:22fc25c6238e 119 while(1)
xinzhizhulaoban 0:22fc25c6238e 120 {
xinzhizhulaoban 0:22fc25c6238e 121 a=pc.getc();
xinzhizhulaoban 0:22fc25c6238e 122 if(a=='7')
xinzhizhulaoban 0:22fc25c6238e 123 {
xinzhizhulaoban 0:22fc25c6238e 124 break;
xinzhizhulaoban 0:22fc25c6238e 125 }
xinzhizhulaoban 0:22fc25c6238e 126 if(a=='8')
xinzhizhulaoban 0:22fc25c6238e 127 {
xinzhizhulaoban 0:22fc25c6238e 128 Digital_Tube=1;
xinzhizhulaoban 0:22fc25c6238e 129 break;
xinzhizhulaoban 0:22fc25c6238e 130 }
xinzhizhulaoban 0:22fc25c6238e 131 if(a=='9')
xinzhizhulaoban 0:22fc25c6238e 132 {
xinzhizhulaoban 0:22fc25c6238e 133 LED=1;
xinzhizhulaoban 0:22fc25c6238e 134 break;
xinzhizhulaoban 0:22fc25c6238e 135 }
xinzhizhulaoban 0:22fc25c6238e 136 if(a=='5')
xinzhizhulaoban 0:22fc25c6238e 137 {
xinzhizhulaoban 0:22fc25c6238e 138 QUESTION1=1;
xinzhizhulaoban 0:22fc25c6238e 139 break;
xinzhizhulaoban 0:22fc25c6238e 140 }
xinzhizhulaoban 0:22fc25c6238e 141 if(a=='6')
xinzhizhulaoban 0:22fc25c6238e 142 {
xinzhizhulaoban 0:22fc25c6238e 143 QUESTION2=1;
xinzhizhulaoban 0:22fc25c6238e 144 break;
xinzhizhulaoban 0:22fc25c6238e 145 }
xinzhizhulaoban 0:22fc25c6238e 146 }
xinzhizhulaoban 0:22fc25c6238e 147 if(Digital_Tube==1 && LED==0 && QUESTION1==0 && QUESTION2==0)
xinzhizhulaoban 0:22fc25c6238e 148 {
xinzhizhulaoban 0:22fc25c6238e 149 start_Digital_Tube=1;
xinzhizhulaoban 0:22fc25c6238e 150 while(1)
xinzhizhulaoban 0:22fc25c6238e 151 {
xinzhizhulaoban 0:22fc25c6238e 152 game_count=game_count+1;
xinzhizhulaoban 0:22fc25c6238e 153 dist = TOF_sensor.getDistance();
xinzhizhulaoban 0:22fc25c6238e 154 if(dist<=100 || dist>=200)
xinzhizhulaoban 0:22fc25c6238e 155 {
xinzhizhulaoban 0:22fc25c6238e 156 distance_over=1;
xinzhizhulaoban 0:22fc25c6238e 157 distance_count=distance_count+1;
xinzhizhulaoban 0:22fc25c6238e 158 if(distance_count==1000)
xinzhizhulaoban 0:22fc25c6238e 159 {
xinzhizhulaoban 0:22fc25c6238e 160 break;
xinzhizhulaoban 0:22fc25c6238e 161 }
xinzhizhulaoban 0:22fc25c6238e 162 }
xinzhizhulaoban 0:22fc25c6238e 163 else
xinzhizhulaoban 0:22fc25c6238e 164 {
xinzhizhulaoban 0:22fc25c6238e 165 distance_over=0;
xinzhizhulaoban 0:22fc25c6238e 166 distance_count=0;
xinzhizhulaoban 0:22fc25c6238e 167 }
xinzhizhulaoban 0:22fc25c6238e 168 if(result1_Digital_Tube==1 && result2_Digital_Tube==0)
xinzhizhulaoban 0:22fc25c6238e 169 {
xinzhizhulaoban 0:22fc25c6238e 170 pc.printf("1");
xinzhizhulaoban 0:22fc25c6238e 171 start_Digital_Tube=0;
xinzhizhulaoban 0:22fc25c6238e 172 break;
xinzhizhulaoban 0:22fc25c6238e 173 }
xinzhizhulaoban 0:22fc25c6238e 174 if(result1_Digital_Tube==0 && result2_Digital_Tube==1)
xinzhizhulaoban 0:22fc25c6238e 175 {
xinzhizhulaoban 0:22fc25c6238e 176 pc.printf("0");
xinzhizhulaoban 0:22fc25c6238e 177 start_Digital_Tube=0;
xinzhizhulaoban 0:22fc25c6238e 178 break;
xinzhizhulaoban 0:22fc25c6238e 179 }
xinzhizhulaoban 0:22fc25c6238e 180 if(game_count==4000)
xinzhizhulaoban 0:22fc25c6238e 181 {
xinzhizhulaoban 0:22fc25c6238e 182 game_count=0;
xinzhizhulaoban 0:22fc25c6238e 183 pc.printf("long time without operating");
xinzhizhulaoban 0:22fc25c6238e 184 break;
xinzhizhulaoban 0:22fc25c6238e 185 }
xinzhizhulaoban 0:22fc25c6238e 186 }
xinzhizhulaoban 0:22fc25c6238e 187 }
xinzhizhulaoban 0:22fc25c6238e 188 if(Digital_Tube==0 && LED==1 && QUESTION1==0 && QUESTION2==0)
xinzhizhulaoban 0:22fc25c6238e 189 {
xinzhizhulaoban 0:22fc25c6238e 190 start_LED=1;
xinzhizhulaoban 0:22fc25c6238e 191 while(1)
xinzhizhulaoban 0:22fc25c6238e 192 {
xinzhizhulaoban 0:22fc25c6238e 193 game_count=game_count+1;
xinzhizhulaoban 0:22fc25c6238e 194 dist = TOF_sensor.getDistance();
xinzhizhulaoban 0:22fc25c6238e 195 if(dist<=100 || dist>=200)
xinzhizhulaoban 0:22fc25c6238e 196 {
xinzhizhulaoban 0:22fc25c6238e 197 distance_over=1;
xinzhizhulaoban 0:22fc25c6238e 198 distance_count=distance_count+1;
xinzhizhulaoban 0:22fc25c6238e 199 if(distance_count==1000)
xinzhizhulaoban 0:22fc25c6238e 200 {
xinzhizhulaoban 0:22fc25c6238e 201 break;
xinzhizhulaoban 0:22fc25c6238e 202 }
xinzhizhulaoban 0:22fc25c6238e 203 }
xinzhizhulaoban 0:22fc25c6238e 204 else
xinzhizhulaoban 0:22fc25c6238e 205 {
xinzhizhulaoban 0:22fc25c6238e 206 distance_over=0;
xinzhizhulaoban 0:22fc25c6238e 207 distance_count=0;
xinzhizhulaoban 0:22fc25c6238e 208 }
xinzhizhulaoban 0:22fc25c6238e 209 if(result1_led==1 && result2_led==0)
xinzhizhulaoban 0:22fc25c6238e 210 {
xinzhizhulaoban 0:22fc25c6238e 211 pc.printf("1");
xinzhizhulaoban 0:22fc25c6238e 212 start_LED=0;
xinzhizhulaoban 0:22fc25c6238e 213 break;
xinzhizhulaoban 0:22fc25c6238e 214 }
xinzhizhulaoban 0:22fc25c6238e 215 if(result1_led==0 && result2_led==1)
xinzhizhulaoban 0:22fc25c6238e 216 {
xinzhizhulaoban 0:22fc25c6238e 217 pc.printf("0");
xinzhizhulaoban 0:22fc25c6238e 218 start_LED=0;
xinzhizhulaoban 0:22fc25c6238e 219 break;
xinzhizhulaoban 0:22fc25c6238e 220 }
xinzhizhulaoban 0:22fc25c6238e 221 if(game_count==4000)
xinzhizhulaoban 0:22fc25c6238e 222 {
xinzhizhulaoban 0:22fc25c6238e 223 game_count=0;
xinzhizhulaoban 0:22fc25c6238e 224 pc.printf("long time without operating");
xinzhizhulaoban 0:22fc25c6238e 225 break;
xinzhizhulaoban 0:22fc25c6238e 226 }
xinzhizhulaoban 0:22fc25c6238e 227 }
xinzhizhulaoban 0:22fc25c6238e 228 }
xinzhizhulaoban 0:22fc25c6238e 229 if(Digital_Tube==0 && LED==0 && QUESTION1==1 && QUESTION2==0)
xinzhizhulaoban 0:22fc25c6238e 230 {
xinzhizhulaoban 0:22fc25c6238e 231 start_question1=1;
xinzhizhulaoban 0:22fc25c6238e 232 start_question2=0;
xinzhizhulaoban 0:22fc25c6238e 233 while(1)
xinzhizhulaoban 0:22fc25c6238e 234 {
xinzhizhulaoban 0:22fc25c6238e 235 game_count=game_count+1;
xinzhizhulaoban 0:22fc25c6238e 236 dist = TOF_sensor.getDistance();
xinzhizhulaoban 0:22fc25c6238e 237 if(dist<=100 && dist>=200)
xinzhizhulaoban 0:22fc25c6238e 238 {
xinzhizhulaoban 0:22fc25c6238e 239 distance_over=1;
xinzhizhulaoban 0:22fc25c6238e 240 distance_count=distance_count+1;
xinzhizhulaoban 0:22fc25c6238e 241 if(distance_count==1000)
xinzhizhulaoban 0:22fc25c6238e 242 {
xinzhizhulaoban 0:22fc25c6238e 243 break;
xinzhizhulaoban 0:22fc25c6238e 244 }
xinzhizhulaoban 0:22fc25c6238e 245 }
xinzhizhulaoban 0:22fc25c6238e 246 else
xinzhizhulaoban 0:22fc25c6238e 247 {
xinzhizhulaoban 0:22fc25c6238e 248 distance_over=0;
xinzhizhulaoban 0:22fc25c6238e 249 distance_count=0;
xinzhizhulaoban 0:22fc25c6238e 250 }
xinzhizhulaoban 0:22fc25c6238e 251 if(result1_question==1 && result2_question==0)
xinzhizhulaoban 0:22fc25c6238e 252 {
xinzhizhulaoban 0:22fc25c6238e 253 pc.printf("1");
xinzhizhulaoban 0:22fc25c6238e 254 start_question1=0;
xinzhizhulaoban 0:22fc25c6238e 255 break;
xinzhizhulaoban 0:22fc25c6238e 256 }
xinzhizhulaoban 0:22fc25c6238e 257 if(result1_question==0 && result2_question==1)
xinzhizhulaoban 0:22fc25c6238e 258 {
xinzhizhulaoban 0:22fc25c6238e 259 pc.printf("0");
xinzhizhulaoban 0:22fc25c6238e 260 start_question1=0;
xinzhizhulaoban 0:22fc25c6238e 261 break;
xinzhizhulaoban 0:22fc25c6238e 262 }
xinzhizhulaoban 0:22fc25c6238e 263 if(game_count==4000)
xinzhizhulaoban 0:22fc25c6238e 264 {
xinzhizhulaoban 0:22fc25c6238e 265 game_count=0;
xinzhizhulaoban 0:22fc25c6238e 266 pc.printf("long time without operating");
xinzhizhulaoban 0:22fc25c6238e 267 break;
xinzhizhulaoban 0:22fc25c6238e 268 }
xinzhizhulaoban 0:22fc25c6238e 269 }
xinzhizhulaoban 0:22fc25c6238e 270 }
xinzhizhulaoban 0:22fc25c6238e 271 if(Digital_Tube==0 && LED==0 && QUESTION1==0 && QUESTION2==1)
xinzhizhulaoban 0:22fc25c6238e 272 {
xinzhizhulaoban 0:22fc25c6238e 273 start_question1=0;
xinzhizhulaoban 0:22fc25c6238e 274 start_question2=1;
xinzhizhulaoban 0:22fc25c6238e 275 while(1)
xinzhizhulaoban 0:22fc25c6238e 276 {
xinzhizhulaoban 0:22fc25c6238e 277 game_count=game_count+1;
xinzhizhulaoban 0:22fc25c6238e 278 dist = TOF_sensor.getDistance();
xinzhizhulaoban 0:22fc25c6238e 279 if(dist<=100 || dist>=200)
xinzhizhulaoban 0:22fc25c6238e 280 {
xinzhizhulaoban 0:22fc25c6238e 281 distance_over=1;
xinzhizhulaoban 0:22fc25c6238e 282 distance_count=distance_count+1;
xinzhizhulaoban 0:22fc25c6238e 283 if(distance_count==1000)
xinzhizhulaoban 0:22fc25c6238e 284 {
xinzhizhulaoban 0:22fc25c6238e 285 break;
xinzhizhulaoban 0:22fc25c6238e 286 }
xinzhizhulaoban 0:22fc25c6238e 287 }
xinzhizhulaoban 0:22fc25c6238e 288 else
xinzhizhulaoban 0:22fc25c6238e 289 {
xinzhizhulaoban 0:22fc25c6238e 290 distance_over=0;
xinzhizhulaoban 0:22fc25c6238e 291 distance_count=0;
xinzhizhulaoban 0:22fc25c6238e 292 }
xinzhizhulaoban 0:22fc25c6238e 293 if(result1_question==1 && result2_question==0)
xinzhizhulaoban 0:22fc25c6238e 294 {
xinzhizhulaoban 0:22fc25c6238e 295 pc.printf("1");
xinzhizhulaoban 0:22fc25c6238e 296 start_question1=0;
xinzhizhulaoban 0:22fc25c6238e 297 start_question2=0;
xinzhizhulaoban 0:22fc25c6238e 298 break;
xinzhizhulaoban 0:22fc25c6238e 299 }
xinzhizhulaoban 0:22fc25c6238e 300 if(result1_question==0 && result2_question==1)
xinzhizhulaoban 0:22fc25c6238e 301 {
xinzhizhulaoban 0:22fc25c6238e 302 pc.printf("0");
xinzhizhulaoban 0:22fc25c6238e 303 start_question1=0;
xinzhizhulaoban 0:22fc25c6238e 304 start_question2=0;
xinzhizhulaoban 0:22fc25c6238e 305 break;
xinzhizhulaoban 0:22fc25c6238e 306 }
xinzhizhulaoban 0:22fc25c6238e 307 if(game_count==4000)
xinzhizhulaoban 0:22fc25c6238e 308 {
xinzhizhulaoban 0:22fc25c6238e 309 game_count=0;
xinzhizhulaoban 0:22fc25c6238e 310 pc.printf("long time without operating");
xinzhizhulaoban 0:22fc25c6238e 311 break;
xinzhizhulaoban 0:22fc25c6238e 312 }
xinzhizhulaoban 0:22fc25c6238e 313 }
xinzhizhulaoban 0:22fc25c6238e 314 }
xinzhizhulaoban 0:22fc25c6238e 315 break;
xinzhizhulaoban 0:22fc25c6238e 316 }
xinzhizhulaoban 0:22fc25c6238e 317 while(user==0 && maintance==1)
xinzhizhulaoban 0:22fc25c6238e 318 {
xinzhizhulaoban 0:22fc25c6238e 319 a=pc.getc();
xinzhizhulaoban 0:22fc25c6238e 320 if(a=='3')
xinzhizhulaoban 0:22fc25c6238e 321 {
xinzhizhulaoban 0:22fc25c6238e 322 start_Digital_Tube=1;
xinzhizhulaoban 0:22fc25c6238e 323 start_LED=1;
xinzhizhulaoban 0:22fc25c6238e 324 start_question1=1;
xinzhizhulaoban 0:22fc25c6238e 325 wait(10);
xinzhizhulaoban 0:22fc25c6238e 326 start_Digital_Tube=0;
xinzhizhulaoban 0:22fc25c6238e 327 start_LED=0;
xinzhizhulaoban 0:22fc25c6238e 328 start_question1=0;
xinzhizhulaoban 0:22fc25c6238e 329 }
xinzhizhulaoban 0:22fc25c6238e 330 if(a=='4')
xinzhizhulaoban 0:22fc25c6238e 331 {
xinzhizhulaoban 0:22fc25c6238e 332 servo_test=1;
xinzhizhulaoban 0:22fc25c6238e 333 wait(10);
xinzhizhulaoban 0:22fc25c6238e 334 servo_test=0;
xinzhizhulaoban 0:22fc25c6238e 335 }
xinzhizhulaoban 0:22fc25c6238e 336 if(a=='5')
xinzhizhulaoban 0:22fc25c6238e 337 {
xinzhizhulaoban 0:22fc25c6238e 338 dist = TOF_sensor.getDistance();
xinzhizhulaoban 0:22fc25c6238e 339 rgb_sensor.getAllColors(rgb_readings);
xinzhizhulaoban 0:22fc25c6238e 340 pc.printf("The distance are %d and the color are Red %d Green %d Blue %d\n",dist,rgb_readings[1],rgb_readings[2],rgb_readings[3]);
xinzhizhulaoban 0:22fc25c6238e 341 }
xinzhizhulaoban 0:22fc25c6238e 342 if(a=='6')
xinzhizhulaoban 0:22fc25c6238e 343 {
xinzhizhulaoban 0:22fc25c6238e 344 while(1)
xinzhizhulaoban 0:22fc25c6238e 345 {
xinzhizhulaoban 0:22fc25c6238e 346 count_color=0;
xinzhizhulaoban 0:22fc25c6238e 347 R=0;
xinzhizhulaoban 0:22fc25c6238e 348 G=0;
xinzhizhulaoban 0:22fc25c6238e 349 B=0;
xinzhizhulaoban 0:22fc25c6238e 350 color1=0;
xinzhizhulaoban 0:22fc25c6238e 351 color2=0;
xinzhizhulaoban 0:22fc25c6238e 352 start_good_supply=0;
xinzhizhulaoban 0:22fc25c6238e 353 while(1)
xinzhizhulaoban 0:22fc25c6238e 354 {
xinzhizhulaoban 0:22fc25c6238e 355 count_color=count_color+1;
xinzhizhulaoban 0:22fc25c6238e 356 rgb_sensor.getAllColors(rgb_readings);
xinzhizhulaoban 0:22fc25c6238e 357 R=R+rgb_readings[1];
xinzhizhulaoban 0:22fc25c6238e 358 G=G+rgb_readings[2];
xinzhizhulaoban 0:22fc25c6238e 359 B=B+rgb_readings[3];
xinzhizhulaoban 0:22fc25c6238e 360 if(count_color>=10)
xinzhizhulaoban 0:22fc25c6238e 361 {
xinzhizhulaoban 0:22fc25c6238e 362 R=R/10;
xinzhizhulaoban 0:22fc25c6238e 363 G=G/10;
xinzhizhulaoban 0:22fc25c6238e 364 B=B/10;
xinzhizhulaoban 0:22fc25c6238e 365 break;
xinzhizhulaoban 0:22fc25c6238e 366 }
xinzhizhulaoban 0:22fc25c6238e 367 }
xinzhizhulaoban 0:22fc25c6238e 368 start_good_supply=1;
xinzhizhulaoban 0:22fc25c6238e 369 if((R-B)>=100 && (G-B)>=100 && R>G)
xinzhizhulaoban 0:22fc25c6238e 370 {
xinzhizhulaoban 0:22fc25c6238e 371 color1=0;
xinzhizhulaoban 0:22fc25c6238e 372 color2=1;
xinzhizhulaoban 0:22fc25c6238e 373 while(1)
xinzhizhulaoban 0:22fc25c6238e 374 {
xinzhizhulaoban 0:22fc25c6238e 375 if(color_over==1)
xinzhizhulaoban 0:22fc25c6238e 376 {
xinzhizhulaoban 0:22fc25c6238e 377 start_good_supply=0;
xinzhizhulaoban 0:22fc25c6238e 378 wait(2);
xinzhizhulaoban 0:22fc25c6238e 379 break;
xinzhizhulaoban 0:22fc25c6238e 380 }
xinzhizhulaoban 0:22fc25c6238e 381 }
xinzhizhulaoban 0:22fc25c6238e 382 }
xinzhizhulaoban 0:22fc25c6238e 383 else if((R-B)>=100 && (R-G)>=100 && (G-B)<=100)
xinzhizhulaoban 0:22fc25c6238e 384 {
xinzhizhulaoban 0:22fc25c6238e 385 color1=1;
xinzhizhulaoban 0:22fc25c6238e 386 color2=0;
xinzhizhulaoban 0:22fc25c6238e 387 while(1)
xinzhizhulaoban 0:22fc25c6238e 388 {
xinzhizhulaoban 0:22fc25c6238e 389 if(color_over==1)
xinzhizhulaoban 0:22fc25c6238e 390 {
xinzhizhulaoban 0:22fc25c6238e 391 start_good_supply=0;
xinzhizhulaoban 0:22fc25c6238e 392 wait(2);
xinzhizhulaoban 0:22fc25c6238e 393 break;
xinzhizhulaoban 0:22fc25c6238e 394 }
xinzhizhulaoban 0:22fc25c6238e 395 }
xinzhizhulaoban 0:22fc25c6238e 396 }
xinzhizhulaoban 0:22fc25c6238e 397 else if((G-R)>=70 && (G-B)>=100)
xinzhizhulaoban 0:22fc25c6238e 398 {
xinzhizhulaoban 0:22fc25c6238e 399 color1=1;
xinzhizhulaoban 0:22fc25c6238e 400 color2=1;
xinzhizhulaoban 0:22fc25c6238e 401 while(1)
xinzhizhulaoban 0:22fc25c6238e 402 {
xinzhizhulaoban 0:22fc25c6238e 403 if(color_over==1)
xinzhizhulaoban 0:22fc25c6238e 404 {
xinzhizhulaoban 0:22fc25c6238e 405 start_good_supply=0;
xinzhizhulaoban 0:22fc25c6238e 406 wait(2);
xinzhizhulaoban 0:22fc25c6238e 407 break;
xinzhizhulaoban 0:22fc25c6238e 408 }
xinzhizhulaoban 0:22fc25c6238e 409 }
xinzhizhulaoban 0:22fc25c6238e 410 }
xinzhizhulaoban 0:22fc25c6238e 411 else
xinzhizhulaoban 0:22fc25c6238e 412 {
xinzhizhulaoban 0:22fc25c6238e 413 good_shut_down=good_shut_down+1;
xinzhizhulaoban 0:22fc25c6238e 414 if(good_shut_down==5)
xinzhizhulaoban 0:22fc25c6238e 415 {
xinzhizhulaoban 0:22fc25c6238e 416 good_shut_down=0;
xinzhizhulaoban 0:22fc25c6238e 417 break;
xinzhizhulaoban 0:22fc25c6238e 418 }
xinzhizhulaoban 0:22fc25c6238e 419 }
xinzhizhulaoban 0:22fc25c6238e 420 }
xinzhizhulaoban 0:22fc25c6238e 421 }
xinzhizhulaoban 0:22fc25c6238e 422 if(a=='7')
xinzhizhulaoban 0:22fc25c6238e 423 {
xinzhizhulaoban 0:22fc25c6238e 424 break;
xinzhizhulaoban 0:22fc25c6238e 425 }
xinzhizhulaoban 0:22fc25c6238e 426
xinzhizhulaoban 0:22fc25c6238e 427 }
xinzhizhulaoban 0:22fc25c6238e 428 }
xinzhizhulaoban 0:22fc25c6238e 429
xinzhizhulaoban 0:22fc25c6238e 430 }