![](/media/cache/group/nUCLEO.png.50x50_q85.jpg)
hmc5883l
Dependencies: HMC5883L LCD4884 MFRC522 eeprom mbed
project.cpp@8:b12138d249ba, 2015-12-08 (annotated)
- Committer:
- 1918june
- Date:
- Tue Dec 08 19:42:26 2015 +0000
- Revision:
- 8:b12138d249ba
- Parent:
- 5:4af4865f462b
- Child:
- 9:b83b9198988d
show laew na
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:930d2bc16788 | 11 | |
1918june | 0:930d2bc16788 | 12 | |
1918june | 0:930d2bc16788 | 13 | EEPROM eeprom(I2C_SDA,I2C_SCL,0); |
1918june | 0:930d2bc16788 | 14 | Serial pc(SERIAL_TX,SERIAL_RX); |
1918june | 0:930d2bc16788 | 15 | LCD4884 lcd; |
1918june | 0:930d2bc16788 | 16 | MFRC522 RFID(D11, D12, D13, D10, MF_RESET); |
1918june | 3:987e54d48f77 | 17 | InterruptIn Sw1(PC_5); |
1918june | 5:4af4865f462b | 18 | AnalogIn Rnd(A2); |
1918june | 3:987e54d48f77 | 19 | DigitalIn Switch1(PC_5); |
1918june | 3:987e54d48f77 | 20 | DigitalIn Switch2(PC_6); |
1918june | 3:987e54d48f77 | 21 | InterruptIn Sw2(PC_6); |
1918june | 5:4af4865f462b | 22 | HMC5883L compass1(D14,D15); |
1918june | 5:4af4865f462b | 23 | HMC5883L compass2(D3,D6); |
1918june | 5:4af4865f462b | 24 | HMC5883L compass3(D5,D7); |
1918june | 5:4af4865f462b | 25 | DigitalOut servoPin(D4); //servo |
1918june | 5:4af4865f462b | 26 | DigitalOut m1inA1(PB_13); //Motor 1 |
1918june | 5:4af4865f462b | 27 | DigitalOut m1inA2(PB_14); |
1918june | 5:4af4865f462b | 28 | DigitalOut m1inB1(PB_15); |
1918june | 5:4af4865f462b | 29 | DigitalOut m1inB2(PB_1); |
1918june | 5:4af4865f462b | 30 | DigitalOut m2inA1(PB_5); //Motor 2 |
1918june | 5:4af4865f462b | 31 | DigitalOut m2inA2(PB_4); |
1918june | 5:4af4865f462b | 32 | DigitalOut m2inB1(PB_10); |
1918june | 5:4af4865f462b | 33 | DigitalOut m2inB2(PA_8); |
1918june | 5:4af4865f462b | 34 | AnalogIn X(A0); // Joystick |
1918june | 5:4af4865f462b | 35 | AnalogIn Y(A1); |
1918june | 5:4af4865f462b | 36 | int16_t data[12] = {0}; |
1918june | 3:987e54d48f77 | 37 | uint8_t mode=0; |
1918june | 8:b12138d249ba | 38 | uint8_t selectitem=0,place=0; |
1918june | 5:4af4865f462b | 39 | |
1918june | 5:4af4865f462b | 40 | void m1step1() |
1918june | 5:4af4865f462b | 41 | { |
1918june | 5:4af4865f462b | 42 | m1inA1 = 0; |
1918june | 5:4af4865f462b | 43 | m1inA2 = 1; |
1918june | 5:4af4865f462b | 44 | m1inB1 = 1; |
1918june | 5:4af4865f462b | 45 | m1inB2 = 0; |
1918june | 5:4af4865f462b | 46 | wait_ms(25); |
1918june | 5:4af4865f462b | 47 | } |
1918june | 5:4af4865f462b | 48 | void m1step2() |
1918june | 5:4af4865f462b | 49 | { |
1918june | 5:4af4865f462b | 50 | m1inA1 = 0; |
1918june | 5:4af4865f462b | 51 | m1inA2 = 1; |
1918june | 5:4af4865f462b | 52 | m1inB1 = 0; |
1918june | 5:4af4865f462b | 53 | m1inB2 = 1; |
1918june | 5:4af4865f462b | 54 | wait_ms(25); |
1918june | 5:4af4865f462b | 55 | } |
1918june | 5:4af4865f462b | 56 | void m1step3() |
1918june | 5:4af4865f462b | 57 | { |
1918june | 5:4af4865f462b | 58 | m1inA1 = 1; |
1918june | 5:4af4865f462b | 59 | m1inA2 = 0; |
1918june | 5:4af4865f462b | 60 | m1inB1 = 0; |
1918june | 5:4af4865f462b | 61 | m1inB2 = 1; |
1918june | 5:4af4865f462b | 62 | wait_ms(25); |
1918june | 5:4af4865f462b | 63 | } |
1918june | 5:4af4865f462b | 64 | void m1step4() |
1918june | 5:4af4865f462b | 65 | { |
1918june | 5:4af4865f462b | 66 | m1inA1 = 1; |
1918june | 5:4af4865f462b | 67 | m1inA2 = 0; |
1918june | 5:4af4865f462b | 68 | m1inB1 = 1; |
1918june | 5:4af4865f462b | 69 | m1inB2 = 0; |
1918june | 5:4af4865f462b | 70 | wait_ms(25); |
1918june | 5:4af4865f462b | 71 | } |
1918june | 5:4af4865f462b | 72 | void m1stopMotor() |
1918june | 5:4af4865f462b | 73 | { |
1918june | 5:4af4865f462b | 74 | m1inA1 = 0; |
1918june | 5:4af4865f462b | 75 | m1inA2 = 0; |
1918june | 5:4af4865f462b | 76 | m1inB1 = 0; |
1918june | 5:4af4865f462b | 77 | m1inB2 = 0; |
1918june | 5:4af4865f462b | 78 | } |
1918june | 5:4af4865f462b | 79 | |
1918june | 5:4af4865f462b | 80 | void m2step1() |
1918june | 5:4af4865f462b | 81 | { |
1918june | 5:4af4865f462b | 82 | m2inA1 = 0; |
1918june | 5:4af4865f462b | 83 | m2inA2 = 1; |
1918june | 5:4af4865f462b | 84 | m2inB1 = 1; |
1918june | 5:4af4865f462b | 85 | m2inB2 = 0; |
1918june | 5:4af4865f462b | 86 | wait_ms(50); |
1918june | 0:930d2bc16788 | 87 | |
1918june | 5:4af4865f462b | 88 | } |
1918june | 5:4af4865f462b | 89 | void m2step2() |
1918june | 5:4af4865f462b | 90 | { |
1918june | 5:4af4865f462b | 91 | m2inA1 = 0; |
1918june | 5:4af4865f462b | 92 | m2inA2 = 1; |
1918june | 5:4af4865f462b | 93 | m2inB1 = 0; |
1918june | 5:4af4865f462b | 94 | m2inB2 = 1; |
1918june | 5:4af4865f462b | 95 | wait_ms(50); |
1918june | 5:4af4865f462b | 96 | } |
1918june | 5:4af4865f462b | 97 | void m2step3() |
1918june | 5:4af4865f462b | 98 | { |
1918june | 5:4af4865f462b | 99 | m2inA1 = 1; |
1918june | 5:4af4865f462b | 100 | m2inA2 = 0; |
1918june | 5:4af4865f462b | 101 | m2inB1 = 0; |
1918june | 5:4af4865f462b | 102 | m2inB2 = 1; |
1918june | 5:4af4865f462b | 103 | wait_ms(50); |
1918june | 5:4af4865f462b | 104 | } |
1918june | 5:4af4865f462b | 105 | void m2step4() |
1918june | 5:4af4865f462b | 106 | { |
1918june | 5:4af4865f462b | 107 | m2inA1 = 1; |
1918june | 5:4af4865f462b | 108 | m2inA2 = 0; |
1918june | 5:4af4865f462b | 109 | m2inB1 = 1; |
1918june | 5:4af4865f462b | 110 | m2inB2 = 0; |
1918june | 5:4af4865f462b | 111 | wait_ms(50); |
1918june | 5:4af4865f462b | 112 | } |
1918june | 5:4af4865f462b | 113 | void m2stopMotor() |
1918june | 5:4af4865f462b | 114 | { |
1918june | 5:4af4865f462b | 115 | m2inA1 = 0; |
1918june | 5:4af4865f462b | 116 | m2inA2 = 0; |
1918june | 5:4af4865f462b | 117 | m2inB1 = 0; |
1918june | 5:4af4865f462b | 118 | m2inB2 = 0; |
1918june | 5:4af4865f462b | 119 | } |
1918june | 5:4af4865f462b | 120 | //PUT |
1918june | 5:4af4865f462b | 121 | void Down() |
1918june | 5:4af4865f462b | 122 | { |
1918june | 5:4af4865f462b | 123 | m1step1(); |
1918june | 5:4af4865f462b | 124 | m1step2(); |
1918june | 5:4af4865f462b | 125 | m1step3(); |
1918june | 5:4af4865f462b | 126 | m1step4(); |
1918june | 5:4af4865f462b | 127 | } |
1918june | 5:4af4865f462b | 128 | void Up() |
1918june | 5:4af4865f462b | 129 | { |
1918june | 5:4af4865f462b | 130 | m1step3(); |
1918june | 5:4af4865f462b | 131 | m1step2(); |
1918june | 5:4af4865f462b | 132 | m1step1(); |
1918june | 5:4af4865f462b | 133 | m1step4(); |
1918june | 5:4af4865f462b | 134 | } |
1918june | 5:4af4865f462b | 135 | void Left() |
1918june | 5:4af4865f462b | 136 | { |
1918june | 5:4af4865f462b | 137 | m2step1(); |
1918june | 5:4af4865f462b | 138 | m2step2(); |
1918june | 5:4af4865f462b | 139 | m2step3(); |
1918june | 5:4af4865f462b | 140 | m2step4(); |
1918june | 5:4af4865f462b | 141 | } |
1918june | 5:4af4865f462b | 142 | void Right() |
1918june | 5:4af4865f462b | 143 | { |
1918june | 5:4af4865f462b | 144 | m2step3(); |
1918june | 5:4af4865f462b | 145 | m2step2(); |
1918june | 5:4af4865f462b | 146 | m2step1(); |
1918june | 5:4af4865f462b | 147 | m2step4(); |
1918june | 5:4af4865f462b | 148 | } |
1918june | 5:4af4865f462b | 149 | void DownRight() |
1918june | 5:4af4865f462b | 150 | { |
1918june | 5:4af4865f462b | 151 | m1step1(); |
1918june | 5:4af4865f462b | 152 | m1step2(); |
1918june | 5:4af4865f462b | 153 | m1step3(); |
1918june | 5:4af4865f462b | 154 | m1step4(); |
1918june | 5:4af4865f462b | 155 | m2step3(); |
1918june | 5:4af4865f462b | 156 | m2step2(); |
1918june | 5:4af4865f462b | 157 | m2step1(); |
1918june | 5:4af4865f462b | 158 | m2step4(); |
1918june | 5:4af4865f462b | 159 | } |
1918june | 5:4af4865f462b | 160 | void DownLeft() |
1918june | 5:4af4865f462b | 161 | { |
1918june | 5:4af4865f462b | 162 | m1step1(); |
1918june | 5:4af4865f462b | 163 | m1step2(); |
1918june | 5:4af4865f462b | 164 | m1step3(); |
1918june | 5:4af4865f462b | 165 | m1step4(); |
1918june | 5:4af4865f462b | 166 | m2step1(); |
1918june | 5:4af4865f462b | 167 | m2step2(); |
1918june | 5:4af4865f462b | 168 | m2step3(); |
1918june | 5:4af4865f462b | 169 | m2step4(); |
1918june | 5:4af4865f462b | 170 | } |
1918june | 5:4af4865f462b | 171 | void UpRight() |
1918june | 5:4af4865f462b | 172 | { |
1918june | 5:4af4865f462b | 173 | m1step3(); |
1918june | 5:4af4865f462b | 174 | m1step2(); |
1918june | 5:4af4865f462b | 175 | m1step1(); |
1918june | 5:4af4865f462b | 176 | m1step4(); |
1918june | 5:4af4865f462b | 177 | m2step3(); |
1918june | 5:4af4865f462b | 178 | m2step2(); |
1918june | 5:4af4865f462b | 179 | m2step1(); |
1918june | 5:4af4865f462b | 180 | m2step4(); |
1918june | 5:4af4865f462b | 181 | } |
1918june | 5:4af4865f462b | 182 | void UpLeft() |
1918june | 5:4af4865f462b | 183 | { |
1918june | 5:4af4865f462b | 184 | m1step3(); |
1918june | 5:4af4865f462b | 185 | m1step2(); |
1918june | 5:4af4865f462b | 186 | m1step1(); |
1918june | 5:4af4865f462b | 187 | m1step4(); |
1918june | 5:4af4865f462b | 188 | m2step1(); |
1918june | 5:4af4865f462b | 189 | m2step2(); |
1918june | 5:4af4865f462b | 190 | m2step3(); |
1918june | 5:4af4865f462b | 191 | m2step4(); |
1918june | 5:4af4865f462b | 192 | } |
1918june | 5:4af4865f462b | 193 | void calibrate() |
1918june | 5:4af4865f462b | 194 | { |
1918june | 5:4af4865f462b | 195 | |
1918june | 5:4af4865f462b | 196 | } |
1918june | 5:4af4865f462b | 197 | float x,y; |
1918june | 5:4af4865f462b | 198 | void control() |
1918june | 5:4af4865f462b | 199 | { |
1918june | 5:4af4865f462b | 200 | |
1918june | 5:4af4865f462b | 201 | x = X.read()*360; |
1918june | 5:4af4865f462b | 202 | y = Y.read()*360; |
1918june | 5:4af4865f462b | 203 | printf("X = %f.2\tY = %f.2\n",x,y); |
1918june | 5:4af4865f462b | 204 | if(x > 200) { |
1918june | 5:4af4865f462b | 205 | Up(); |
1918june | 5:4af4865f462b | 206 | } |
1918june | 5:4af4865f462b | 207 | if(x < 160) { |
1918june | 5:4af4865f462b | 208 | Down(); |
1918june | 5:4af4865f462b | 209 | } |
1918june | 5:4af4865f462b | 210 | if(y > 200) { |
1918june | 5:4af4865f462b | 211 | Right(); |
1918june | 5:4af4865f462b | 212 | } |
1918june | 5:4af4865f462b | 213 | if(y < 160) { |
1918june | 5:4af4865f462b | 214 | Left(); |
1918june | 5:4af4865f462b | 215 | } |
1918june | 5:4af4865f462b | 216 | |
1918june | 5:4af4865f462b | 217 | } |
1918june | 5:4af4865f462b | 218 | void servodown() |
1918june | 5:4af4865f462b | 219 | { |
1918june | 5:4af4865f462b | 220 | for(int i=0; i<=6; i++) { |
1918june | 5:4af4865f462b | 221 | servoPin = 1; |
1918june | 5:4af4865f462b | 222 | wait_us(500); |
1918june | 5:4af4865f462b | 223 | servoPin = 0; |
1918june | 5:4af4865f462b | 224 | wait(1); |
1918june | 5:4af4865f462b | 225 | } |
1918june | 5:4af4865f462b | 226 | } |
1918june | 5:4af4865f462b | 227 | void servoup() |
1918june | 5:4af4865f462b | 228 | { |
1918june | 5:4af4865f462b | 229 | for(int i=0; i<=6; i++) { |
1918june | 5:4af4865f462b | 230 | servoPin = 1; |
1918june | 5:4af4865f462b | 231 | wait_us(2500); |
1918june | 5:4af4865f462b | 232 | servoPin = 0; |
1918june | 5:4af4865f462b | 233 | wait(1); |
1918june | 5:4af4865f462b | 234 | } |
1918june | 5:4af4865f462b | 235 | } |
1918june | 5:4af4865f462b | 236 | void read(int16_t data[9]) |
1918june | 5:4af4865f462b | 237 | { |
1918june | 5:4af4865f462b | 238 | int16_t a[3],b[3],c[3]; |
1918june | 5:4af4865f462b | 239 | |
1918june | 5:4af4865f462b | 240 | int w=0; |
1918june | 5:4af4865f462b | 241 | |
1918june | 5:4af4865f462b | 242 | compass1.getXYZ(a); |
1918june | 5:4af4865f462b | 243 | compass2.getXYZ(b); |
1918june | 5:4af4865f462b | 244 | compass3.getXYZ(c); |
1918june | 5:4af4865f462b | 245 | for(int i=0; i<3; i++) { |
1918june | 5:4af4865f462b | 246 | data[w]=a[i]/10; |
1918june | 5:4af4865f462b | 247 | w++; |
1918june | 5:4af4865f462b | 248 | } |
1918june | 5:4af4865f462b | 249 | |
1918june | 5:4af4865f462b | 250 | for(int i=0; i<3; i++) { |
1918june | 5:4af4865f462b | 251 | data[w]=b[i]/10; |
1918june | 5:4af4865f462b | 252 | w++; |
1918june | 5:4af4865f462b | 253 | } |
1918june | 5:4af4865f462b | 254 | for(int i=0; i<3; i++) { |
1918june | 5:4af4865f462b | 255 | data[w]=c[i]/10; |
1918june | 5:4af4865f462b | 256 | w++; |
1918june | 5:4af4865f462b | 257 | } |
1918june | 5:4af4865f462b | 258 | |
1918june | 5:4af4865f462b | 259 | } |
1918june | 5:4af4865f462b | 260 | |
1918june | 5:4af4865f462b | 261 | void dataprint(int16_t data[9]) |
1918june | 5:4af4865f462b | 262 | { |
1918june | 5:4af4865f462b | 263 | for(int c=0; c<9; c++) { |
1918june | 5:4af4865f462b | 264 | printf("%d ",data[c]); |
1918june | 5:4af4865f462b | 265 | // if((c+1)%3==0){printf("||");} |
1918june | 5:4af4865f462b | 266 | } |
1918june | 5:4af4865f462b | 267 | printf("\n"); |
1918june | 5:4af4865f462b | 268 | } |
1918june | 3:987e54d48f77 | 269 | void ItrSw1() |
1918june | 3:987e54d48f77 | 270 | { |
1918june | 3:987e54d48f77 | 271 | mode=1; |
1918june | 3:987e54d48f77 | 272 | } |
1918june | 3:987e54d48f77 | 273 | |
1918june | 3:987e54d48f77 | 274 | void ItrSw2() |
1918june | 3:987e54d48f77 | 275 | { |
1918june | 3:987e54d48f77 | 276 | mode=2; |
1918june | 3:987e54d48f77 | 277 | } |
1918june | 3:987e54d48f77 | 278 | |
1918june | 3:987e54d48f77 | 279 | void ItrSw3() |
1918june | 3:987e54d48f77 | 280 | { |
1918june | 3:987e54d48f77 | 281 | mode=0; |
1918june | 3:987e54d48f77 | 282 | } |
1918june | 3:987e54d48f77 | 283 | void printstring(int x,int y,string s,int n,int m) |
1918june | 3:987e54d48f77 | 284 | { |
1918june | 2:38376c7c1685 | 285 | int k=0; |
1918june | 2:38376c7c1685 | 286 | lcd.LCD_set_XY(x,y); |
1918june | 3:987e54d48f77 | 287 | while(k<n) { |
1918june | 3:987e54d48f77 | 288 | lcd.LCD_write_char(s[k],m); |
1918june | 3:987e54d48f77 | 289 | k++; |
1918june | 2:38376c7c1685 | 290 | } |
1918june | 2:38376c7c1685 | 291 | } |
1918june | 0:930d2bc16788 | 292 | |
1918june | 0:930d2bc16788 | 293 | int main() |
1918june | 0:930d2bc16788 | 294 | { |
1918june | 0:930d2bc16788 | 295 | pc.baud(9600); |
1918june | 3:987e54d48f77 | 296 | Sw1.rise(&ItrSw1); |
1918june | 3:987e54d48f77 | 297 | Sw2.rise(&ItrSw2); |
1918june | 5:4af4865f462b | 298 | compass1.init(); |
1918june | 5:4af4865f462b | 299 | compass2.init(); |
1918june | 5:4af4865f462b | 300 | compass3.init(); |
1918june | 3:987e54d48f77 | 301 | string NameJune="Natthanicha",recieveNameJune,SurJune="Jamroonpan",recieveSurJune,IdJune="57340500023",recieveIdJune; //June start @ 1-36 |
1918june | 3:987e54d48f77 | 302 | string NameO="Sirawat",recieveNameO,SurO="Sok",recieveSurO,IdO="57340500071",recieveIdO; |
1918june | 3:987e54d48f77 | 303 | uint8_t UID[8],recieveUID[8]; |
1918june | 2:38376c7c1685 | 304 | UID[0]=106; |
1918june | 2:38376c7c1685 | 305 | UID[1]=224; |
1918june | 2:38376c7c1685 | 306 | UID[2]=37; |
1918june | 2:38376c7c1685 | 307 | UID[3]=231; |
1918june | 3:987e54d48f77 | 308 | UID[4]=106; |
1918june | 3:987e54d48f77 | 309 | UID[5]=76; |
1918june | 3:987e54d48f77 | 310 | UID[6]=39; |
1918june | 3:987e54d48f77 | 311 | UID[7]=231; |
1918june | 3:987e54d48f77 | 312 | |
1918june | 3:987e54d48f77 | 313 | eeprom.write(1,&NameJune,11); |
1918june | 3:987e54d48f77 | 314 | wait_us(1); |
1918june | 3:987e54d48f77 | 315 | eeprom.write(12,&SurJune,10); |
1918june | 3:987e54d48f77 | 316 | wait_us(1); |
1918june | 3:987e54d48f77 | 317 | eeprom.write(22,&IdJune,11); |
1918june | 3:987e54d48f77 | 318 | wait_us(1); |
1918june | 3:987e54d48f77 | 319 | eeprom.write(41,&NameO,7); |
1918june | 3:987e54d48f77 | 320 | wait_us(1); |
1918june | 3:987e54d48f77 | 321 | eeprom.write(48,&SurO,3); |
1918june | 3:987e54d48f77 | 322 | wait_us(1); |
1918june | 3:987e54d48f77 | 323 | eeprom.write(51,&IdO,11); |
1918june | 3:987e54d48f77 | 324 | wait_us(1); |
1918june | 3:987e54d48f77 | 325 | eeprom.write(81,UID,8); |
1918june | 3:987e54d48f77 | 326 | wait_us(1); |
1918june | 3:987e54d48f77 | 327 | eeprom.read(1,&recieveNameJune,11); |
1918june | 3:987e54d48f77 | 328 | eeprom.read(12,&recieveSurJune,10); |
1918june | 3:987e54d48f77 | 329 | eeprom.read(22,&recieveIdJune,11); |
1918june | 3:987e54d48f77 | 330 | eeprom.read(41,&recieveNameO,7); |
1918june | 3:987e54d48f77 | 331 | eeprom.read(48,&recieveSurO,3); |
1918june | 3:987e54d48f77 | 332 | eeprom.read(51,&recieveIdO,11); |
1918june | 3:987e54d48f77 | 333 | eeprom.read(81,recieveUID,8); |
1918june | 3:987e54d48f77 | 334 | //pc.printf("%s\n",recieveNameJune); |
1918june | 3:987e54d48f77 | 335 | //pc.printf("%s\n",recieveSurJune); |
1918june | 3:987e54d48f77 | 336 | //pc.printf("%s\n",recieveIdJune); |
1918june | 3:987e54d48f77 | 337 | //pc.printf("%s\n",recieveNameO); |
1918june | 3:987e54d48f77 | 338 | //pc.printf("%s\n",recieveSurO); |
1918june | 3:987e54d48f77 | 339 | //pc.printf("%s\n",recieveIdO); |
1918june | 3:987e54d48f77 | 340 | //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 | 341 | RFID.PCD_Init(); |
1918june | 0:930d2bc16788 | 342 | lcd.LCD_init(); |
1918june | 0:930d2bc16788 | 343 | lcd.backlight(ON); |
1918june | 2:38376c7c1685 | 344 | wait(2); |
1918june | 0:930d2bc16788 | 345 | lcd.LCD_clear(); |
1918june | 3:987e54d48f77 | 346 | while(1) { |
1918june | 4:b56a8a051fdd | 347 | lcd.LCD_write_string(0,0,"SCAN ID CARD",0); |
1918june | 0:930d2bc16788 | 348 | if ( ! RFID.PICC_IsNewCardPresent()) // Look for new cards |
1918june | 0:930d2bc16788 | 349 | continue; |
1918june | 0:930d2bc16788 | 350 | if ( ! RFID.PICC_ReadCardSerial()) // Select one of the cards |
1918june | 4:b56a8a051fdd | 351 | |
1918june | 0:930d2bc16788 | 352 | continue; |
1918june | 0:930d2bc16788 | 353 | pc.printf("Card UID: "); |
1918june | 0:930d2bc16788 | 354 | for (uint8_t i = 0; i < RFID.uid.size; i++) |
1918june | 0:930d2bc16788 | 355 | pc.printf(" %d", RFID.uid.uidByte[i]); |
1918june | 0:930d2bc16788 | 356 | printf("\n\r"); |
1918june | 3:987e54d48f77 | 357 | 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 | 358 | //จำ |
1918june | 3:987e54d48f77 | 359 | pc.printf("%s\t%s\t%s\n",recieveNameJune,recieveSurJune,recieveIdJune); |
1918june | 4:b56a8a051fdd | 360 | lcd.LCD_clear(); |
1918june | 3:987e54d48f77 | 361 | string name,sur; |
1918june | 3:987e54d48f77 | 362 | eeprom.read(1,&name,11); |
1918june | 3:987e54d48f77 | 363 | eeprom.read(12,&sur,10); |
1918june | 3:987e54d48f77 | 364 | printstring(0,0,name,11,0); |
1918june | 3:987e54d48f77 | 365 | printstring(0,1,sur,10,0); |
1918june | 3:987e54d48f77 | 366 | //lcd.LCD_clear(); |
1918june | 3:987e54d48f77 | 367 | } |
1918june | 3:987e54d48f77 | 368 | 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 | 369 | pc.printf("%s\t%s\t%s\n",recieveNameO,recieveSurO,recieveIdO); |
1918june | 2:38376c7c1685 | 370 | |
1918june | 5:4af4865f462b | 371 | |
1918june | 3:987e54d48f77 | 372 | string name,sur; |
1918june | 4:b56a8a051fdd | 373 | lcd.LCD_clear(); |
1918june | 3:987e54d48f77 | 374 | eeprom.read(41,&name,7); |
1918june | 3:987e54d48f77 | 375 | eeprom.read(48,&sur,3); |
1918june | 3:987e54d48f77 | 376 | printstring(0,0,name,7,0); |
1918june | 3:987e54d48f77 | 377 | printstring(0,1,sur,3,0); |
1918june | 0:930d2bc16788 | 378 | } |
1918june | 3:987e54d48f77 | 379 | //wait(2); |
1918june | 3:987e54d48f77 | 380 | //lcd.LCD_clear(); |
1918june | 3:987e54d48f77 | 381 | lcd.LCD_write_string(0,2,"1 select item",0); |
1918june | 3:987e54d48f77 | 382 | lcd.LCD_write_string(0,3,"2 select place",0); |
1918june | 4:b56a8a051fdd | 383 | //lcd.LCD_write_string(40,5,"cancel",0); |
1918june | 3:987e54d48f77 | 384 | while(1) { |
1918june | 3:987e54d48f77 | 385 | if(mode==1) { |
1918june | 3:987e54d48f77 | 386 | printf("1"); |
1918june | 3:987e54d48f77 | 387 | lcd.LCD_clear(); |
1918june | 3:987e54d48f77 | 388 | lcd.LCD_write_string(0,0,"mode 1",0); |
1918june | 3:987e54d48f77 | 389 | lcd.LCD_write_string(0,1,"select item",0); |
1918june | 3:987e54d48f77 | 390 | while(1) { |
1918june | 3:987e54d48f77 | 391 | if(Switch1.read()==1) { |
1918june | 3:987e54d48f77 | 392 | char str[10]; |
1918june | 3:987e54d48f77 | 393 | selectitem++; |
1918june | 3:987e54d48f77 | 394 | if(selectitem > 9) |
1918june | 3:987e54d48f77 | 395 | selectitem=1; |
1918june | 3:987e54d48f77 | 396 | wait(0.2); |
1918june | 3:987e54d48f77 | 397 | sprintf(str,"item : %d",selectitem); |
1918june | 3:987e54d48f77 | 398 | printstring(3,2,str,8,0); |
1918june | 3:987e54d48f77 | 399 | } |
1918june | 4:b56a8a051fdd | 400 | if(Switch2.read()==1 && selectitem !=0) { |
1918june | 4:b56a8a051fdd | 401 | mode=1; |
1918june | 3:987e54d48f77 | 402 | char str[10]; |
1918june | 3:987e54d48f77 | 403 | place=((int) (Rnd.read()*1000))%4 +1; |
1918june | 3:987e54d48f77 | 404 | wait(0.2); |
1918june | 3:987e54d48f77 | 405 | sprintf(str,"place :%d",place); |
1918june | 3:987e54d48f77 | 406 | printstring(3,3,str,8,0); |
1918june | 3:987e54d48f77 | 407 | break; |
1918june | 3:987e54d48f77 | 408 | } |
1918june | 3:987e54d48f77 | 409 | } |
1918june | 5:4af4865f462b | 410 | wait(1); |
1918june | 5:4af4865f462b | 411 | while(1) { // |
1918june | 5:4af4865f462b | 412 | control(); |
1918june | 5:4af4865f462b | 413 | if(Switch2.read()==1) { |
1918june | 5:4af4865f462b | 414 | mode=1; |
1918june | 5:4af4865f462b | 415 | servodown();//servo down |
1918june | 5:4af4865f462b | 416 | read(data); |
1918june | 5:4af4865f462b | 417 | dataprint(data); |
1918june | 5:4af4865f462b | 418 | wait_ms(500); |
1918june | 5:4af4865f462b | 419 | servoup();//servo up |
1918june | 5:4af4865f462b | 420 | } |
1918june | 3:987e54d48f77 | 421 | } |
1918june | 3:987e54d48f77 | 422 | } |
1918june | 3:987e54d48f77 | 423 | if(mode==2) {//selectplace |
1918june | 3:987e54d48f77 | 424 | printf("2"); |
1918june | 3:987e54d48f77 | 425 | lcd.LCD_clear(); |
1918june | 3:987e54d48f77 | 426 | lcd.LCD_write_string(0,0,"mode 2",0); |
1918june | 3:987e54d48f77 | 427 | lcd.LCD_write_string(0,1,"select place",0); |
1918june | 3:987e54d48f77 | 428 | while(1) { |
1918june | 3:987e54d48f77 | 429 | if(Switch1.read()==1) { |
1918june | 4:b56a8a051fdd | 430 | mode=2; |
1918june | 3:987e54d48f77 | 431 | char str[10]; |
1918june | 3:987e54d48f77 | 432 | place++; |
1918june | 3:987e54d48f77 | 433 | if(place > 4) |
1918june | 3:987e54d48f77 | 434 | place=1; |
1918june | 3:987e54d48f77 | 435 | wait(0.2); |
1918june | 3:987e54d48f77 | 436 | sprintf(str,"place : %d",place); |
1918june | 3:987e54d48f77 | 437 | printstring(3,2,str,9,0); |
1918june | 3:987e54d48f77 | 438 | } |
1918june | 4:b56a8a051fdd | 439 | if(Switch2.read()==1 && place!=0) { |
1918june | 3:987e54d48f77 | 440 | char str[10]; |
1918june | 3:987e54d48f77 | 441 | selectitem=((int) (Rnd.read()*1000))%9 +1; |
1918june | 3:987e54d48f77 | 442 | wait(0.2); |
1918june | 3:987e54d48f77 | 443 | sprintf(str,"item : %d",selectitem); |
1918june | 3:987e54d48f77 | 444 | printstring(3,3,str,8,0); |
1918june | 3:987e54d48f77 | 445 | break; |
1918june | 3:987e54d48f77 | 446 | } |
1918june | 4:b56a8a051fdd | 447 | } |
1918june | 5:4af4865f462b | 448 | wait(1); |
1918june | 5:4af4865f462b | 449 | |
1918june | 4:b56a8a051fdd | 450 | } |
1918june | 2:38376c7c1685 | 451 | |
1918june | 5:4af4865f462b | 452 | printf("mode=%d\n",mode); |
1918june | 3:987e54d48f77 | 453 | |
1918june | 4:b56a8a051fdd | 454 | } //end while mode loop |
1918june | 4:b56a8a051fdd | 455 | } |
1918june | 3:987e54d48f77 | 456 | |
1918june | 3:987e54d48f77 | 457 | } |
1918june | 4:b56a8a051fdd | 458 |