hmc5883l

Dependencies:   HMC5883L LCD4884 MFRC522 eeprom mbed

Files at this revision

API Documentation at this revision

Comitter:
1918june
Date:
Tue Dec 08 18:58:50 2015 +0000
Parent:
5:4af4865f462b
Child:
7:7daef23ab362
Commit message:
edit pin tub

Changed in this revision

project.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/project.cpp	Tue Dec 08 17:42:29 2015 +0000
+++ b/project.cpp	Tue Dec 08 18:58:50 2015 +0000
@@ -8,7 +8,8 @@
 
 // KL25Z Pin for MFRC522 reset
 #define MF_RESET    D9
-
+#define POINT_June  100
+#define POINT_O     101
 
 EEPROM  eeprom(I2C_SDA,I2C_SCL,0);
 Serial  pc(SERIAL_TX,SERIAL_RX);
@@ -35,6 +36,9 @@
 AnalogIn Y(A1);
 int16_t data[12] = {0};
 uint8_t mode=0;
+uint8_t point=0;
+uint8_t selectitem=0,place=0;
+uint8_t user=0;
 
 void m1step1()
 {
@@ -189,10 +193,108 @@
     m2step3();
     m2step4();
 }
-void calibrate()
+/*void calibrate()
 {
+    for(int i=0; i<=4; i++) {
+        servoPin = 1;
+        wait_us(700);
+        servoPin = 0;
+        wait(1);
+    }
+    read(data);
+    dataprint(data);//อ่านค่าSensor*************************
+    for(int i=0; i<=6; i++) {
+        servoPin = 1;
+        wait_us(2500);
+        servoPin = 0;
+        wait(1);
+    }
 
-}
+    for (int i=0; i<=250; i++) {
+        m1step1();
+        m1step2();
+        m1step3();
+        m1step4();
+    }
+
+    m1stopMotor();
+    wait(1);
+
+    for(int i=0; i<=4; i++) {
+        servoPin = 1;
+        wait_us(700);
+        servoPin = 0;
+        wait(1);
+    }
+    read(data);
+    dataprint(data);//อ่านค่าSensor*************************
+    for(int i=0; i<=6; i++) {
+        servoPin = 1;
+        wait_us(2500);
+        servoPin = 0;
+        wait(1);
+    }
+
+    for (int i=0; i<=300; i++) {
+        m2step1();
+        m2step2();
+        m2step3();
+        m2step4();
+    }
+
+    m2stopMotor();
+    wait(1);
+
+    for(int i=0; i<=4; i++) {
+        servoPin = 1;
+        wait_us(700);
+        servoPin = 0;
+        wait(1);
+    }
+    read(data);
+    dataprint(data);//อ่านค่าSensor*************************
+    for(int i=0; i<=6; i++) {
+        servoPin = 1;
+        wait_us(2500);
+        servoPin = 0;
+        wait(1);
+    }
+
+    for (int i=0; i<=250; i++) {
+        m1step3();
+        m1step2();
+        m1step1();
+        m1step4();
+    }
+
+    m1stopMotor();
+    wait(1);
+
+    for(int i=0; i<=4; i++) {
+        servoPin = 1;
+        wait_us(700);
+        servoPin = 0;
+        wait(1);
+    }
+    read(data);
+    dataprint(data);//อ่านค่าSensor*************************
+    for(int i=0; i<=6; i++) {
+        servoPin = 1;
+        wait_us(2500);
+        servoPin = 0;
+        wait(1);
+    }
+
+    for (int i=0; i<=300; i++) {
+        m2step3();
+        m2step2();
+        m2step1();
+        m2step4();
+    }
+
+    m2stopMotor();
+    wait(1);
+}*/
 float x,y;
 void control()
 {
@@ -212,6 +314,7 @@
     if(y < 160) {
         Left();
     }
+    
 
 }
 void servodown()
@@ -288,13 +391,17 @@
         k++;
     }
 }
-
+int checkpoint()
+{
+    int P;
+    //P=(sd89sd9))) วิธีการคำนวณคะแนน
+    return P;
+}
 int main()
 {
     pc.baud(9600);
     Sw1.rise(&ItrSw1);
     Sw2.rise(&ItrSw2);
-    Sw3.rise(&ItrSw3);
     compass1.init();
     compass2.init();
     compass3.init();
@@ -358,28 +465,31 @@
             //จำ
             pc.printf("%s\t%s\t%s\n",recieveNameJune,recieveSurJune,recieveIdJune);
             lcd.LCD_clear();
-            string name,sur;
+            string name,sur,point;//June
             eeprom.read(1,&name,11);
             eeprom.read(12,&sur,10);
+            eeprom.read(POINT_June,&point,1);
             printstring(0,0,name,11,0);
             printstring(0,1,sur,10,0);
-            //lcd.LCD_clear();
+            printstring(0,2,point,1,0);
+            user=1;
         }
         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] ) {
             pc.printf("%s\t%s\t%s\n",recieveNameO,recieveSurO,recieveIdO);
-
-
-            string name,sur;
+            string name,sur,point;
             lcd.LCD_clear();
             eeprom.read(41,&name,7);
             eeprom.read(48,&sur,3);
+            eeprom.read(POINT_O,&point,1);
             printstring(0,0,name,7,0);
             printstring(0,1,sur,3,0);
+            printstring(0,2,point,1,0);
+            user=2;
         }
         //wait(2);
         //lcd.LCD_clear();
-        lcd.LCD_write_string(0,2,"1 select item",0);
-        lcd.LCD_write_string(0,3,"2 select place",0);
+        lcd.LCD_write_string(0,4,"1 select item",0);
+        lcd.LCD_write_string(0,5,"2 select place",0);
         //lcd.LCD_write_string(40,5,"cancel",0);
         while(1) {
             if(mode==1) {
@@ -411,14 +521,26 @@
                 while(1) { //
                     control();
                     if(Switch2.read()==1) {
+                        char str[12];
                         mode=1;
                         servodown();//servo down
                         read(data);
                         dataprint(data);
                         wait_ms(500);
                         servoup();//servo up
+                        point = checkpoint();
+                        sprintf(str,"point = %d",point);
+                        lcd.LCD_clear();
+                        lcd.LCD_write_string(0,1,str,0);
+                        if(user==1)
+                            eeprom.write(POINT_June,&point,1);
+                        if(user==2)
+                            eeprom.write(POINT_O,&point,1);
+                        break;
                     }
                 }
+
+
             }
             if(mode==2) {//selectplace
                 printf("2");
@@ -446,13 +568,32 @@
                     }
                 }
                 wait(1);
- 
-            }
-
-            printf("mode=%d\n",mode);
+                while(1) { //
+                    control();
+                    if(Switch2.read()==1) {
+                        char str[12];
+                        mode=1;
+                        servodown();//servo down
+                        read(data);
+                        dataprint(data);
+                        wait_ms(500);
+                        servoup();//servo up
+                        point = checkpoint();
+                        sprintf(str,"point = %d",point);
+                        lcd.LCD_clear();
+                        lcd.LCD_write_string(0,1,str,0);
+                        if(user==1)
+                            eeprom.write(POINT_June,&point,1);
+                        if(user==2)
+                            eeprom.write(POINT_O,&point,1);
+                        break;
+                    }
+                }
 
-        }  //end while mode loop
-    }
+                printf("mode=%d\n",mode);
 
+            }  //end while mode loop
+        }
+
+    }
 }
-