hmc5883l

Dependencies:   HMC5883L LCD4884 MFRC522 eeprom mbed

Committer:
1918june
Date:
Tue Dec 08 18:58:50 2015 +0000
Revision:
6:4923616c7321
Parent:
5:4af4865f462b
Child:
7:7daef23ab362
edit pin tub

Who changed what in which revision?

UserRevisionLine numberNew contents of line
1918june 0:930d2bc16788 1 #include "mbed.h"
1918june 0:930d2bc16788 2 #include "LCD4884.h"
1918june 0:930d2bc16788 3 #include "MFRC522.h"
1918june 0:930d2bc16788 4 #include "eeprom.h"
1918june 0:930d2bc16788 5 #include "string.h"
1918june 5:4af4865f462b 6 #include "HMC5883L.h"
1918june 0:930d2bc16788 7
1918june 0:930d2bc16788 8
1918june 0:930d2bc16788 9 // KL25Z Pin for MFRC522 reset
1918june 0:930d2bc16788 10 #define MF_RESET D9
1918june 6:4923616c7321 11 #define POINT_June 100
1918june 6:4923616c7321 12 #define POINT_O 101
1918june 0:930d2bc16788 13
1918june 0:930d2bc16788 14 EEPROM eeprom(I2C_SDA,I2C_SCL,0);
1918june 0:930d2bc16788 15 Serial pc(SERIAL_TX,SERIAL_RX);
1918june 0:930d2bc16788 16 LCD4884 lcd;
1918june 0:930d2bc16788 17 MFRC522 RFID(D11, D12, D13, D10, MF_RESET);
1918june 3:987e54d48f77 18 InterruptIn Sw1(PC_5);
1918june 5:4af4865f462b 19 AnalogIn Rnd(A2);
1918june 3:987e54d48f77 20 DigitalIn Switch1(PC_5);
1918june 3:987e54d48f77 21 DigitalIn Switch2(PC_6);
1918june 3:987e54d48f77 22 InterruptIn Sw2(PC_6);
1918june 5:4af4865f462b 23 HMC5883L compass1(D14,D15);
1918june 5:4af4865f462b 24 HMC5883L compass2(D3,D6);
1918june 5:4af4865f462b 25 HMC5883L compass3(D5,D7);
1918june 5:4af4865f462b 26 DigitalOut servoPin(D4); //servo
1918june 5:4af4865f462b 27 DigitalOut m1inA1(PB_13); //Motor 1
1918june 5:4af4865f462b 28 DigitalOut m1inA2(PB_14);
1918june 5:4af4865f462b 29 DigitalOut m1inB1(PB_15);
1918june 5:4af4865f462b 30 DigitalOut m1inB2(PB_1);
1918june 5:4af4865f462b 31 DigitalOut m2inA1(PB_5); //Motor 2
1918june 5:4af4865f462b 32 DigitalOut m2inA2(PB_4);
1918june 5:4af4865f462b 33 DigitalOut m2inB1(PB_10);
1918june 5:4af4865f462b 34 DigitalOut m2inB2(PA_8);
1918june 5:4af4865f462b 35 AnalogIn X(A0); // Joystick
1918june 5:4af4865f462b 36 AnalogIn Y(A1);
1918june 5:4af4865f462b 37 int16_t data[12] = {0};
1918june 3:987e54d48f77 38 uint8_t mode=0;
1918june 6:4923616c7321 39 uint8_t point=0;
1918june 6:4923616c7321 40 uint8_t selectitem=0,place=0;
1918june 6:4923616c7321 41 uint8_t user=0;
1918june 5:4af4865f462b 42
1918june 5:4af4865f462b 43 void m1step1()
1918june 5:4af4865f462b 44 {
1918june 5:4af4865f462b 45 m1inA1 = 0;
1918june 5:4af4865f462b 46 m1inA2 = 1;
1918june 5:4af4865f462b 47 m1inB1 = 1;
1918june 5:4af4865f462b 48 m1inB2 = 0;
1918june 5:4af4865f462b 49 wait_ms(25);
1918june 5:4af4865f462b 50 }
1918june 5:4af4865f462b 51 void m1step2()
1918june 5:4af4865f462b 52 {
1918june 5:4af4865f462b 53 m1inA1 = 0;
1918june 5:4af4865f462b 54 m1inA2 = 1;
1918june 5:4af4865f462b 55 m1inB1 = 0;
1918june 5:4af4865f462b 56 m1inB2 = 1;
1918june 5:4af4865f462b 57 wait_ms(25);
1918june 5:4af4865f462b 58 }
1918june 5:4af4865f462b 59 void m1step3()
1918june 5:4af4865f462b 60 {
1918june 5:4af4865f462b 61 m1inA1 = 1;
1918june 5:4af4865f462b 62 m1inA2 = 0;
1918june 5:4af4865f462b 63 m1inB1 = 0;
1918june 5:4af4865f462b 64 m1inB2 = 1;
1918june 5:4af4865f462b 65 wait_ms(25);
1918june 5:4af4865f462b 66 }
1918june 5:4af4865f462b 67 void m1step4()
1918june 5:4af4865f462b 68 {
1918june 5:4af4865f462b 69 m1inA1 = 1;
1918june 5:4af4865f462b 70 m1inA2 = 0;
1918june 5:4af4865f462b 71 m1inB1 = 1;
1918june 5:4af4865f462b 72 m1inB2 = 0;
1918june 5:4af4865f462b 73 wait_ms(25);
1918june 5:4af4865f462b 74 }
1918june 5:4af4865f462b 75 void m1stopMotor()
1918june 5:4af4865f462b 76 {
1918june 5:4af4865f462b 77 m1inA1 = 0;
1918june 5:4af4865f462b 78 m1inA2 = 0;
1918june 5:4af4865f462b 79 m1inB1 = 0;
1918june 5:4af4865f462b 80 m1inB2 = 0;
1918june 5:4af4865f462b 81 }
1918june 5:4af4865f462b 82
1918june 5:4af4865f462b 83 void m2step1()
1918june 5:4af4865f462b 84 {
1918june 5:4af4865f462b 85 m2inA1 = 0;
1918june 5:4af4865f462b 86 m2inA2 = 1;
1918june 5:4af4865f462b 87 m2inB1 = 1;
1918june 5:4af4865f462b 88 m2inB2 = 0;
1918june 5:4af4865f462b 89 wait_ms(50);
1918june 0:930d2bc16788 90
1918june 5:4af4865f462b 91 }
1918june 5:4af4865f462b 92 void m2step2()
1918june 5:4af4865f462b 93 {
1918june 5:4af4865f462b 94 m2inA1 = 0;
1918june 5:4af4865f462b 95 m2inA2 = 1;
1918june 5:4af4865f462b 96 m2inB1 = 0;
1918june 5:4af4865f462b 97 m2inB2 = 1;
1918june 5:4af4865f462b 98 wait_ms(50);
1918june 5:4af4865f462b 99 }
1918june 5:4af4865f462b 100 void m2step3()
1918june 5:4af4865f462b 101 {
1918june 5:4af4865f462b 102 m2inA1 = 1;
1918june 5:4af4865f462b 103 m2inA2 = 0;
1918june 5:4af4865f462b 104 m2inB1 = 0;
1918june 5:4af4865f462b 105 m2inB2 = 1;
1918june 5:4af4865f462b 106 wait_ms(50);
1918june 5:4af4865f462b 107 }
1918june 5:4af4865f462b 108 void m2step4()
1918june 5:4af4865f462b 109 {
1918june 5:4af4865f462b 110 m2inA1 = 1;
1918june 5:4af4865f462b 111 m2inA2 = 0;
1918june 5:4af4865f462b 112 m2inB1 = 1;
1918june 5:4af4865f462b 113 m2inB2 = 0;
1918june 5:4af4865f462b 114 wait_ms(50);
1918june 5:4af4865f462b 115 }
1918june 5:4af4865f462b 116 void m2stopMotor()
1918june 5:4af4865f462b 117 {
1918june 5:4af4865f462b 118 m2inA1 = 0;
1918june 5:4af4865f462b 119 m2inA2 = 0;
1918june 5:4af4865f462b 120 m2inB1 = 0;
1918june 5:4af4865f462b 121 m2inB2 = 0;
1918june 5:4af4865f462b 122 }
1918june 5:4af4865f462b 123 //PUT
1918june 5:4af4865f462b 124 void Down()
1918june 5:4af4865f462b 125 {
1918june 5:4af4865f462b 126 m1step1();
1918june 5:4af4865f462b 127 m1step2();
1918june 5:4af4865f462b 128 m1step3();
1918june 5:4af4865f462b 129 m1step4();
1918june 5:4af4865f462b 130 }
1918june 5:4af4865f462b 131 void Up()
1918june 5:4af4865f462b 132 {
1918june 5:4af4865f462b 133 m1step3();
1918june 5:4af4865f462b 134 m1step2();
1918june 5:4af4865f462b 135 m1step1();
1918june 5:4af4865f462b 136 m1step4();
1918june 5:4af4865f462b 137 }
1918june 5:4af4865f462b 138 void Left()
1918june 5:4af4865f462b 139 {
1918june 5:4af4865f462b 140 m2step1();
1918june 5:4af4865f462b 141 m2step2();
1918june 5:4af4865f462b 142 m2step3();
1918june 5:4af4865f462b 143 m2step4();
1918june 5:4af4865f462b 144 }
1918june 5:4af4865f462b 145 void Right()
1918june 5:4af4865f462b 146 {
1918june 5:4af4865f462b 147 m2step3();
1918june 5:4af4865f462b 148 m2step2();
1918june 5:4af4865f462b 149 m2step1();
1918june 5:4af4865f462b 150 m2step4();
1918june 5:4af4865f462b 151 }
1918june 5:4af4865f462b 152 void DownRight()
1918june 5:4af4865f462b 153 {
1918june 5:4af4865f462b 154 m1step1();
1918june 5:4af4865f462b 155 m1step2();
1918june 5:4af4865f462b 156 m1step3();
1918june 5:4af4865f462b 157 m1step4();
1918june 5:4af4865f462b 158 m2step3();
1918june 5:4af4865f462b 159 m2step2();
1918june 5:4af4865f462b 160 m2step1();
1918june 5:4af4865f462b 161 m2step4();
1918june 5:4af4865f462b 162 }
1918june 5:4af4865f462b 163 void DownLeft()
1918june 5:4af4865f462b 164 {
1918june 5:4af4865f462b 165 m1step1();
1918june 5:4af4865f462b 166 m1step2();
1918june 5:4af4865f462b 167 m1step3();
1918june 5:4af4865f462b 168 m1step4();
1918june 5:4af4865f462b 169 m2step1();
1918june 5:4af4865f462b 170 m2step2();
1918june 5:4af4865f462b 171 m2step3();
1918june 5:4af4865f462b 172 m2step4();
1918june 5:4af4865f462b 173 }
1918june 5:4af4865f462b 174 void UpRight()
1918june 5:4af4865f462b 175 {
1918june 5:4af4865f462b 176 m1step3();
1918june 5:4af4865f462b 177 m1step2();
1918june 5:4af4865f462b 178 m1step1();
1918june 5:4af4865f462b 179 m1step4();
1918june 5:4af4865f462b 180 m2step3();
1918june 5:4af4865f462b 181 m2step2();
1918june 5:4af4865f462b 182 m2step1();
1918june 5:4af4865f462b 183 m2step4();
1918june 5:4af4865f462b 184 }
1918june 5:4af4865f462b 185 void UpLeft()
1918june 5:4af4865f462b 186 {
1918june 5:4af4865f462b 187 m1step3();
1918june 5:4af4865f462b 188 m1step2();
1918june 5:4af4865f462b 189 m1step1();
1918june 5:4af4865f462b 190 m1step4();
1918june 5:4af4865f462b 191 m2step1();
1918june 5:4af4865f462b 192 m2step2();
1918june 5:4af4865f462b 193 m2step3();
1918june 5:4af4865f462b 194 m2step4();
1918june 5:4af4865f462b 195 }
1918june 6:4923616c7321 196 /*void calibrate()
1918june 5:4af4865f462b 197 {
1918june 6:4923616c7321 198 for(int i=0; i<=4; i++) {
1918june 6:4923616c7321 199 servoPin = 1;
1918june 6:4923616c7321 200 wait_us(700);
1918june 6:4923616c7321 201 servoPin = 0;
1918june 6:4923616c7321 202 wait(1);
1918june 6:4923616c7321 203 }
1918june 6:4923616c7321 204 read(data);
1918june 6:4923616c7321 205 dataprint(data);//อ่านค่าSensor*************************
1918june 6:4923616c7321 206 for(int i=0; i<=6; i++) {
1918june 6:4923616c7321 207 servoPin = 1;
1918june 6:4923616c7321 208 wait_us(2500);
1918june 6:4923616c7321 209 servoPin = 0;
1918june 6:4923616c7321 210 wait(1);
1918june 6:4923616c7321 211 }
1918june 5:4af4865f462b 212
1918june 6:4923616c7321 213 for (int i=0; i<=250; i++) {
1918june 6:4923616c7321 214 m1step1();
1918june 6:4923616c7321 215 m1step2();
1918june 6:4923616c7321 216 m1step3();
1918june 6:4923616c7321 217 m1step4();
1918june 6:4923616c7321 218 }
1918june 6:4923616c7321 219
1918june 6:4923616c7321 220 m1stopMotor();
1918june 6:4923616c7321 221 wait(1);
1918june 6:4923616c7321 222
1918june 6:4923616c7321 223 for(int i=0; i<=4; i++) {
1918june 6:4923616c7321 224 servoPin = 1;
1918june 6:4923616c7321 225 wait_us(700);
1918june 6:4923616c7321 226 servoPin = 0;
1918june 6:4923616c7321 227 wait(1);
1918june 6:4923616c7321 228 }
1918june 6:4923616c7321 229 read(data);
1918june 6:4923616c7321 230 dataprint(data);//อ่านค่าSensor*************************
1918june 6:4923616c7321 231 for(int i=0; i<=6; i++) {
1918june 6:4923616c7321 232 servoPin = 1;
1918june 6:4923616c7321 233 wait_us(2500);
1918june 6:4923616c7321 234 servoPin = 0;
1918june 6:4923616c7321 235 wait(1);
1918june 6:4923616c7321 236 }
1918june 6:4923616c7321 237
1918june 6:4923616c7321 238 for (int i=0; i<=300; i++) {
1918june 6:4923616c7321 239 m2step1();
1918june 6:4923616c7321 240 m2step2();
1918june 6:4923616c7321 241 m2step3();
1918june 6:4923616c7321 242 m2step4();
1918june 6:4923616c7321 243 }
1918june 6:4923616c7321 244
1918june 6:4923616c7321 245 m2stopMotor();
1918june 6:4923616c7321 246 wait(1);
1918june 6:4923616c7321 247
1918june 6:4923616c7321 248 for(int i=0; i<=4; i++) {
1918june 6:4923616c7321 249 servoPin = 1;
1918june 6:4923616c7321 250 wait_us(700);
1918june 6:4923616c7321 251 servoPin = 0;
1918june 6:4923616c7321 252 wait(1);
1918june 6:4923616c7321 253 }
1918june 6:4923616c7321 254 read(data);
1918june 6:4923616c7321 255 dataprint(data);//อ่านค่าSensor*************************
1918june 6:4923616c7321 256 for(int i=0; i<=6; i++) {
1918june 6:4923616c7321 257 servoPin = 1;
1918june 6:4923616c7321 258 wait_us(2500);
1918june 6:4923616c7321 259 servoPin = 0;
1918june 6:4923616c7321 260 wait(1);
1918june 6:4923616c7321 261 }
1918june 6:4923616c7321 262
1918june 6:4923616c7321 263 for (int i=0; i<=250; i++) {
1918june 6:4923616c7321 264 m1step3();
1918june 6:4923616c7321 265 m1step2();
1918june 6:4923616c7321 266 m1step1();
1918june 6:4923616c7321 267 m1step4();
1918june 6:4923616c7321 268 }
1918june 6:4923616c7321 269
1918june 6:4923616c7321 270 m1stopMotor();
1918june 6:4923616c7321 271 wait(1);
1918june 6:4923616c7321 272
1918june 6:4923616c7321 273 for(int i=0; i<=4; i++) {
1918june 6:4923616c7321 274 servoPin = 1;
1918june 6:4923616c7321 275 wait_us(700);
1918june 6:4923616c7321 276 servoPin = 0;
1918june 6:4923616c7321 277 wait(1);
1918june 6:4923616c7321 278 }
1918june 6:4923616c7321 279 read(data);
1918june 6:4923616c7321 280 dataprint(data);//อ่านค่าSensor*************************
1918june 6:4923616c7321 281 for(int i=0; i<=6; i++) {
1918june 6:4923616c7321 282 servoPin = 1;
1918june 6:4923616c7321 283 wait_us(2500);
1918june 6:4923616c7321 284 servoPin = 0;
1918june 6:4923616c7321 285 wait(1);
1918june 6:4923616c7321 286 }
1918june 6:4923616c7321 287
1918june 6:4923616c7321 288 for (int i=0; i<=300; i++) {
1918june 6:4923616c7321 289 m2step3();
1918june 6:4923616c7321 290 m2step2();
1918june 6:4923616c7321 291 m2step1();
1918june 6:4923616c7321 292 m2step4();
1918june 6:4923616c7321 293 }
1918june 6:4923616c7321 294
1918june 6:4923616c7321 295 m2stopMotor();
1918june 6:4923616c7321 296 wait(1);
1918june 6:4923616c7321 297 }*/
1918june 5:4af4865f462b 298 float x,y;
1918june 5:4af4865f462b 299 void control()
1918june 5:4af4865f462b 300 {
1918june 5:4af4865f462b 301
1918june 5:4af4865f462b 302 x = X.read()*360;
1918june 5:4af4865f462b 303 y = Y.read()*360;
1918june 5:4af4865f462b 304 printf("X = %f.2\tY = %f.2\n",x,y);
1918june 5:4af4865f462b 305 if(x > 200) {
1918june 5:4af4865f462b 306 Up();
1918june 5:4af4865f462b 307 }
1918june 5:4af4865f462b 308 if(x < 160) {
1918june 5:4af4865f462b 309 Down();
1918june 5:4af4865f462b 310 }
1918june 5:4af4865f462b 311 if(y > 200) {
1918june 5:4af4865f462b 312 Right();
1918june 5:4af4865f462b 313 }
1918june 5:4af4865f462b 314 if(y < 160) {
1918june 5:4af4865f462b 315 Left();
1918june 5:4af4865f462b 316 }
1918june 6:4923616c7321 317
1918june 5:4af4865f462b 318
1918june 5:4af4865f462b 319 }
1918june 5:4af4865f462b 320 void servodown()
1918june 5:4af4865f462b 321 {
1918june 5:4af4865f462b 322 for(int i=0; i<=6; i++) {
1918june 5:4af4865f462b 323 servoPin = 1;
1918june 5:4af4865f462b 324 wait_us(500);
1918june 5:4af4865f462b 325 servoPin = 0;
1918june 5:4af4865f462b 326 wait(1);
1918june 5:4af4865f462b 327 }
1918june 5:4af4865f462b 328 }
1918june 5:4af4865f462b 329 void servoup()
1918june 5:4af4865f462b 330 {
1918june 5:4af4865f462b 331 for(int i=0; i<=6; i++) {
1918june 5:4af4865f462b 332 servoPin = 1;
1918june 5:4af4865f462b 333 wait_us(2500);
1918june 5:4af4865f462b 334 servoPin = 0;
1918june 5:4af4865f462b 335 wait(1);
1918june 5:4af4865f462b 336 }
1918june 5:4af4865f462b 337 }
1918june 5:4af4865f462b 338 void read(int16_t data[9])
1918june 5:4af4865f462b 339 {
1918june 5:4af4865f462b 340 int16_t a[3],b[3],c[3];
1918june 5:4af4865f462b 341
1918june 5:4af4865f462b 342 int w=0;
1918june 5:4af4865f462b 343
1918june 5:4af4865f462b 344 compass1.getXYZ(a);
1918june 5:4af4865f462b 345 compass2.getXYZ(b);
1918june 5:4af4865f462b 346 compass3.getXYZ(c);
1918june 5:4af4865f462b 347 for(int i=0; i<3; i++) {
1918june 5:4af4865f462b 348 data[w]=a[i]/10;
1918june 5:4af4865f462b 349 w++;
1918june 5:4af4865f462b 350 }
1918june 5:4af4865f462b 351
1918june 5:4af4865f462b 352 for(int i=0; i<3; i++) {
1918june 5:4af4865f462b 353 data[w]=b[i]/10;
1918june 5:4af4865f462b 354 w++;
1918june 5:4af4865f462b 355 }
1918june 5:4af4865f462b 356 for(int i=0; i<3; i++) {
1918june 5:4af4865f462b 357 data[w]=c[i]/10;
1918june 5:4af4865f462b 358 w++;
1918june 5:4af4865f462b 359 }
1918june 5:4af4865f462b 360
1918june 5:4af4865f462b 361 }
1918june 5:4af4865f462b 362
1918june 5:4af4865f462b 363 void dataprint(int16_t data[9])
1918june 5:4af4865f462b 364 {
1918june 5:4af4865f462b 365 for(int c=0; c<9; c++) {
1918june 5:4af4865f462b 366 printf("%d ",data[c]);
1918june 5:4af4865f462b 367 // if((c+1)%3==0){printf("||");}
1918june 5:4af4865f462b 368 }
1918june 5:4af4865f462b 369 printf("\n");
1918june 5:4af4865f462b 370 }
1918june 3:987e54d48f77 371 void ItrSw1()
1918june 3:987e54d48f77 372 {
1918june 3:987e54d48f77 373 mode=1;
1918june 3:987e54d48f77 374 }
1918june 3:987e54d48f77 375
1918june 3:987e54d48f77 376 void ItrSw2()
1918june 3:987e54d48f77 377 {
1918june 3:987e54d48f77 378 mode=2;
1918june 3:987e54d48f77 379 }
1918june 3:987e54d48f77 380
1918june 3:987e54d48f77 381 void ItrSw3()
1918june 3:987e54d48f77 382 {
1918june 3:987e54d48f77 383 mode=0;
1918june 3:987e54d48f77 384 }
1918june 3:987e54d48f77 385 void printstring(int x,int y,string s,int n,int m)
1918june 3:987e54d48f77 386 {
1918june 2:38376c7c1685 387 int k=0;
1918june 2:38376c7c1685 388 lcd.LCD_set_XY(x,y);
1918june 3:987e54d48f77 389 while(k<n) {
1918june 3:987e54d48f77 390 lcd.LCD_write_char(s[k],m);
1918june 3:987e54d48f77 391 k++;
1918june 2:38376c7c1685 392 }
1918june 2:38376c7c1685 393 }
1918june 6:4923616c7321 394 int checkpoint()
1918june 6:4923616c7321 395 {
1918june 6:4923616c7321 396 int P;
1918june 6:4923616c7321 397 //P=(sd89sd9))) วิธีการคำนวณคะแนน
1918june 6:4923616c7321 398 return P;
1918june 6:4923616c7321 399 }
1918june 0:930d2bc16788 400 int main()
1918june 0:930d2bc16788 401 {
1918june 0:930d2bc16788 402 pc.baud(9600);
1918june 3:987e54d48f77 403 Sw1.rise(&ItrSw1);
1918june 3:987e54d48f77 404 Sw2.rise(&ItrSw2);
1918june 5:4af4865f462b 405 compass1.init();
1918june 5:4af4865f462b 406 compass2.init();
1918june 5:4af4865f462b 407 compass3.init();
1918june 3:987e54d48f77 408 string NameJune="Natthanicha",recieveNameJune,SurJune="Jamroonpan",recieveSurJune,IdJune="57340500023",recieveIdJune; //June start @ 1-36
1918june 3:987e54d48f77 409 string NameO="Sirawat",recieveNameO,SurO="Sok",recieveSurO,IdO="57340500071",recieveIdO;
1918june 3:987e54d48f77 410 uint8_t UID[8],recieveUID[8];
1918june 2:38376c7c1685 411 UID[0]=106;
1918june 2:38376c7c1685 412 UID[1]=224;
1918june 2:38376c7c1685 413 UID[2]=37;
1918june 2:38376c7c1685 414 UID[3]=231;
1918june 3:987e54d48f77 415 UID[4]=106;
1918june 3:987e54d48f77 416 UID[5]=76;
1918june 3:987e54d48f77 417 UID[6]=39;
1918june 3:987e54d48f77 418 UID[7]=231;
1918june 3:987e54d48f77 419
1918june 3:987e54d48f77 420 eeprom.write(1,&NameJune,11);
1918june 3:987e54d48f77 421 wait_us(1);
1918june 3:987e54d48f77 422 eeprom.write(12,&SurJune,10);
1918june 3:987e54d48f77 423 wait_us(1);
1918june 3:987e54d48f77 424 eeprom.write(22,&IdJune,11);
1918june 3:987e54d48f77 425 wait_us(1);
1918june 3:987e54d48f77 426 eeprom.write(41,&NameO,7);
1918june 3:987e54d48f77 427 wait_us(1);
1918june 3:987e54d48f77 428 eeprom.write(48,&SurO,3);
1918june 3:987e54d48f77 429 wait_us(1);
1918june 3:987e54d48f77 430 eeprom.write(51,&IdO,11);
1918june 3:987e54d48f77 431 wait_us(1);
1918june 3:987e54d48f77 432 eeprom.write(81,UID,8);
1918june 3:987e54d48f77 433 wait_us(1);
1918june 3:987e54d48f77 434 eeprom.read(1,&recieveNameJune,11);
1918june 3:987e54d48f77 435 eeprom.read(12,&recieveSurJune,10);
1918june 3:987e54d48f77 436 eeprom.read(22,&recieveIdJune,11);
1918june 3:987e54d48f77 437 eeprom.read(41,&recieveNameO,7);
1918june 3:987e54d48f77 438 eeprom.read(48,&recieveSurO,3);
1918june 3:987e54d48f77 439 eeprom.read(51,&recieveIdO,11);
1918june 3:987e54d48f77 440 eeprom.read(81,recieveUID,8);
1918june 3:987e54d48f77 441 //pc.printf("%s\n",recieveNameJune);
1918june 3:987e54d48f77 442 //pc.printf("%s\n",recieveSurJune);
1918june 3:987e54d48f77 443 //pc.printf("%s\n",recieveIdJune);
1918june 3:987e54d48f77 444 //pc.printf("%s\n",recieveNameO);
1918june 3:987e54d48f77 445 //pc.printf("%s\n",recieveSurO);
1918june 3:987e54d48f77 446 //pc.printf("%s\n",recieveIdO);
1918june 3:987e54d48f77 447 //pc.printf("%d %d %d %d %d %d %d %d\n",recieveUID[0],recieveUID[1],recieveUID[2],recieveUID[3],recieveUID[4],recieveUID[5],recieveUID[6],recieveUID[7]);
1918june 2:38376c7c1685 448 RFID.PCD_Init();
1918june 0:930d2bc16788 449 lcd.LCD_init();
1918june 0:930d2bc16788 450 lcd.backlight(ON);
1918june 2:38376c7c1685 451 wait(2);
1918june 0:930d2bc16788 452 lcd.LCD_clear();
1918june 3:987e54d48f77 453 while(1) {
1918june 4:b56a8a051fdd 454 lcd.LCD_write_string(0,0,"SCAN ID CARD",0);
1918june 0:930d2bc16788 455 if ( ! RFID.PICC_IsNewCardPresent()) // Look for new cards
1918june 0:930d2bc16788 456 continue;
1918june 0:930d2bc16788 457 if ( ! RFID.PICC_ReadCardSerial()) // Select one of the cards
1918june 4:b56a8a051fdd 458
1918june 0:930d2bc16788 459 continue;
1918june 0:930d2bc16788 460 pc.printf("Card UID: ");
1918june 0:930d2bc16788 461 for (uint8_t i = 0; i < RFID.uid.size; i++)
1918june 0:930d2bc16788 462 pc.printf(" %d", RFID.uid.uidByte[i]);
1918june 0:930d2bc16788 463 printf("\n\r");
1918june 3:987e54d48f77 464 if( RFID.uid.uidByte[0]==recieveUID[0] && RFID.uid.uidByte[1]==recieveUID[1] && RFID.uid.uidByte[2]==recieveUID[2] && RFID.uid.uidByte[3]==recieveUID[3] ) {
1918june 3:987e54d48f77 465 //จำ
1918june 3:987e54d48f77 466 pc.printf("%s\t%s\t%s\n",recieveNameJune,recieveSurJune,recieveIdJune);
1918june 4:b56a8a051fdd 467 lcd.LCD_clear();
1918june 6:4923616c7321 468 string name,sur,point;//June
1918june 3:987e54d48f77 469 eeprom.read(1,&name,11);
1918june 3:987e54d48f77 470 eeprom.read(12,&sur,10);
1918june 6:4923616c7321 471 eeprom.read(POINT_June,&point,1);
1918june 3:987e54d48f77 472 printstring(0,0,name,11,0);
1918june 3:987e54d48f77 473 printstring(0,1,sur,10,0);
1918june 6:4923616c7321 474 printstring(0,2,point,1,0);
1918june 6:4923616c7321 475 user=1;
1918june 3:987e54d48f77 476 }
1918june 3:987e54d48f77 477 if( RFID.uid.uidByte[0]==recieveUID[4] && RFID.uid.uidByte[1]==recieveUID[5] && RFID.uid.uidByte[2]==recieveUID[6] && RFID.uid.uidByte[3]==recieveUID[7] ) {
1918june 3:987e54d48f77 478 pc.printf("%s\t%s\t%s\n",recieveNameO,recieveSurO,recieveIdO);
1918june 6:4923616c7321 479 string name,sur,point;
1918june 4:b56a8a051fdd 480 lcd.LCD_clear();
1918june 3:987e54d48f77 481 eeprom.read(41,&name,7);
1918june 3:987e54d48f77 482 eeprom.read(48,&sur,3);
1918june 6:4923616c7321 483 eeprom.read(POINT_O,&point,1);
1918june 3:987e54d48f77 484 printstring(0,0,name,7,0);
1918june 3:987e54d48f77 485 printstring(0,1,sur,3,0);
1918june 6:4923616c7321 486 printstring(0,2,point,1,0);
1918june 6:4923616c7321 487 user=2;
1918june 0:930d2bc16788 488 }
1918june 3:987e54d48f77 489 //wait(2);
1918june 3:987e54d48f77 490 //lcd.LCD_clear();
1918june 6:4923616c7321 491 lcd.LCD_write_string(0,4,"1 select item",0);
1918june 6:4923616c7321 492 lcd.LCD_write_string(0,5,"2 select place",0);
1918june 4:b56a8a051fdd 493 //lcd.LCD_write_string(40,5,"cancel",0);
1918june 3:987e54d48f77 494 while(1) {
1918june 3:987e54d48f77 495 if(mode==1) {
1918june 3:987e54d48f77 496 printf("1");
1918june 3:987e54d48f77 497 lcd.LCD_clear();
1918june 3:987e54d48f77 498 lcd.LCD_write_string(0,0,"mode 1",0);
1918june 3:987e54d48f77 499 lcd.LCD_write_string(0,1,"select item",0);
1918june 3:987e54d48f77 500 while(1) {
1918june 3:987e54d48f77 501 if(Switch1.read()==1) {
1918june 3:987e54d48f77 502 char str[10];
1918june 3:987e54d48f77 503 selectitem++;
1918june 3:987e54d48f77 504 if(selectitem > 9)
1918june 3:987e54d48f77 505 selectitem=1;
1918june 3:987e54d48f77 506 wait(0.2);
1918june 3:987e54d48f77 507 sprintf(str,"item : %d",selectitem);
1918june 3:987e54d48f77 508 printstring(3,2,str,8,0);
1918june 3:987e54d48f77 509 }
1918june 4:b56a8a051fdd 510 if(Switch2.read()==1 && selectitem !=0) {
1918june 4:b56a8a051fdd 511 mode=1;
1918june 3:987e54d48f77 512 char str[10];
1918june 3:987e54d48f77 513 place=((int) (Rnd.read()*1000))%4 +1;
1918june 3:987e54d48f77 514 wait(0.2);
1918june 3:987e54d48f77 515 sprintf(str,"place :%d",place);
1918june 3:987e54d48f77 516 printstring(3,3,str,8,0);
1918june 3:987e54d48f77 517 break;
1918june 3:987e54d48f77 518 }
1918june 3:987e54d48f77 519 }
1918june 5:4af4865f462b 520 wait(1);
1918june 5:4af4865f462b 521 while(1) { //
1918june 5:4af4865f462b 522 control();
1918june 5:4af4865f462b 523 if(Switch2.read()==1) {
1918june 6:4923616c7321 524 char str[12];
1918june 5:4af4865f462b 525 mode=1;
1918june 5:4af4865f462b 526 servodown();//servo down
1918june 5:4af4865f462b 527 read(data);
1918june 5:4af4865f462b 528 dataprint(data);
1918june 5:4af4865f462b 529 wait_ms(500);
1918june 5:4af4865f462b 530 servoup();//servo up
1918june 6:4923616c7321 531 point = checkpoint();
1918june 6:4923616c7321 532 sprintf(str,"point = %d",point);
1918june 6:4923616c7321 533 lcd.LCD_clear();
1918june 6:4923616c7321 534 lcd.LCD_write_string(0,1,str,0);
1918june 6:4923616c7321 535 if(user==1)
1918june 6:4923616c7321 536 eeprom.write(POINT_June,&point,1);
1918june 6:4923616c7321 537 if(user==2)
1918june 6:4923616c7321 538 eeprom.write(POINT_O,&point,1);
1918june 6:4923616c7321 539 break;
1918june 5:4af4865f462b 540 }
1918june 3:987e54d48f77 541 }
1918june 6:4923616c7321 542
1918june 6:4923616c7321 543
1918june 3:987e54d48f77 544 }
1918june 3:987e54d48f77 545 if(mode==2) {//selectplace
1918june 3:987e54d48f77 546 printf("2");
1918june 3:987e54d48f77 547 lcd.LCD_clear();
1918june 3:987e54d48f77 548 lcd.LCD_write_string(0,0,"mode 2",0);
1918june 3:987e54d48f77 549 lcd.LCD_write_string(0,1,"select place",0);
1918june 3:987e54d48f77 550 while(1) {
1918june 3:987e54d48f77 551 if(Switch1.read()==1) {
1918june 4:b56a8a051fdd 552 mode=2;
1918june 3:987e54d48f77 553 char str[10];
1918june 3:987e54d48f77 554 place++;
1918june 3:987e54d48f77 555 if(place > 4)
1918june 3:987e54d48f77 556 place=1;
1918june 3:987e54d48f77 557 wait(0.2);
1918june 3:987e54d48f77 558 sprintf(str,"place : %d",place);
1918june 3:987e54d48f77 559 printstring(3,2,str,9,0);
1918june 3:987e54d48f77 560 }
1918june 4:b56a8a051fdd 561 if(Switch2.read()==1 && place!=0) {
1918june 3:987e54d48f77 562 char str[10];
1918june 3:987e54d48f77 563 selectitem=((int) (Rnd.read()*1000))%9 +1;
1918june 3:987e54d48f77 564 wait(0.2);
1918june 3:987e54d48f77 565 sprintf(str,"item : %d",selectitem);
1918june 3:987e54d48f77 566 printstring(3,3,str,8,0);
1918june 3:987e54d48f77 567 break;
1918june 3:987e54d48f77 568 }
1918june 4:b56a8a051fdd 569 }
1918june 5:4af4865f462b 570 wait(1);
1918june 6:4923616c7321 571 while(1) { //
1918june 6:4923616c7321 572 control();
1918june 6:4923616c7321 573 if(Switch2.read()==1) {
1918june 6:4923616c7321 574 char str[12];
1918june 6:4923616c7321 575 mode=1;
1918june 6:4923616c7321 576 servodown();//servo down
1918june 6:4923616c7321 577 read(data);
1918june 6:4923616c7321 578 dataprint(data);
1918june 6:4923616c7321 579 wait_ms(500);
1918june 6:4923616c7321 580 servoup();//servo up
1918june 6:4923616c7321 581 point = checkpoint();
1918june 6:4923616c7321 582 sprintf(str,"point = %d",point);
1918june 6:4923616c7321 583 lcd.LCD_clear();
1918june 6:4923616c7321 584 lcd.LCD_write_string(0,1,str,0);
1918june 6:4923616c7321 585 if(user==1)
1918june 6:4923616c7321 586 eeprom.write(POINT_June,&point,1);
1918june 6:4923616c7321 587 if(user==2)
1918june 6:4923616c7321 588 eeprom.write(POINT_O,&point,1);
1918june 6:4923616c7321 589 break;
1918june 6:4923616c7321 590 }
1918june 6:4923616c7321 591 }
1918june 3:987e54d48f77 592
1918june 6:4923616c7321 593 printf("mode=%d\n",mode);
1918june 3:987e54d48f77 594
1918june 6:4923616c7321 595 } //end while mode loop
1918june 6:4923616c7321 596 }
1918june 6:4923616c7321 597
1918june 6:4923616c7321 598 }
1918june 3:987e54d48f77 599 }