Outils pour utilisateurs

Outils du site


id-12la

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
id-12la [2018/05/25 22:57]
colin
id-12la [2018/05/26 03:14] (Version actuelle)
colin
Ligne 28: Ligne 28:
 #include <​SoftwareSerial.h>​ #include <​SoftwareSerial.h>​
  
 +// ID12LA
 const int RFIDResetPin = 13; const int RFIDResetPin = 13;
 +const int MAXCHARACTER = 10;
 +char tagString[MAXCHARACTER];​
 +unsigned long timeElapsedMs;​
 +
 // software serial #2: RX = digital pin 8, TX = digital pin 9 // software serial #2: RX = digital pin 8, TX = digital pin 9
 // on the Mega, use other pins instead, since 8 and 9 don't work on the Mega // on the Mega, use other pins instead, since 8 and 9 don't work on the Mega
Ligne 36: Ligne 41:
   Serial.begin(9600);​   Serial.begin(9600);​
  
 +  // ID12LA
   portId12LA.begin(9600);​   portId12LA.begin(9600);​
- 
   pinMode(RFIDResetPin,​ OUTPUT);   pinMode(RFIDResetPin,​ OUTPUT);
   digitalWrite(RFIDResetPin,​ HIGH);   digitalWrite(RFIDResetPin,​ HIGH);
Ligne 44: Ligne 49:
 void loop(){ void loop(){
  
-  char tagString[13];​ + // ID12LA
-  int index = 0; +
-  boolean reading = false;+
  
-  portId12LA.listen();​ +  ​if(millis() - timeElapsedMs > 150) 
-  while(portId12LA.available()){ +  { 
- +    timeElapsedMs = millis(); 
-    int readByte = portId12LA.read();​ //read next available byte +     
- +    int index = 0; 
-    if(readByte == 2) reading ​= true; //begining of tag +    boolean bReading = false; 
-    if(readByte == 3) reading ​= false; //end of tag +    boolean bNewTag = false; 
- +    ​portId12LA.listen();​ 
-    if(reading ​&& readByte != 2 && readByte != 10 && readByte != 13){ +    while(portId12LA.available()){ 
-      //store the tag +   
-      tagString[index] = readByte; +      int readByte = portId12LA.read();​ //read next available byte 
-      index ++;+   
 +      if(readByte == 2)  
 +      { 
 +        bReading ​= true; //begining of tag 
 +        index = 0; 
 +      } 
 +      ​if(readByte == 3)  
 +      { 
 +        bReading ​= false; //end of tag 
 +        ​bNewTag = true; 
 +      } 
 +   
 +      ​if(bReading ​&& readByte != 2 && readByte != 10 && readByte != 13){ 
 +        //store the tag 
 +        ​if(index < MAXCHARACTER) 
 +          ​tagString[index] = readByte; 
 +        index ++; 
 +      }
     }     }
 +  ​
 +    if(bNewTag)
 +      sendTag(tagString);​ //Send tag
 +      ​
 +    clearTag(tagString);​ //Clear the char of all value
 +    resetReader();​ //Reset the RFID reader
   }   }
- 
-  checkTag(tagString);​ //Check if it is a match 
-  clearTag(tagString);​ //Clear the char of all value 
-  resetReader();​ //eset the RFID reader 
 } }
  
-void checkTag(char tag[]){+ 
 +void sendTag(char tag[]){
 ///////////////////////////////////​ ///////////////////////////////////​
 //Check the read tag against known tags //Check the read tag against known tags
 ///////////////////////////////////​ ///////////////////////////////////​
- +  ​if(strlen(tag) == 0)  
-  ​if(strlen(tag) == 0) return; //empty, no need to contunue +     return; //empty, no need to contunue 
-   ​Serial.println(tag);​ //read out any unknown tag+  Serial.println(tag);​ //read out any unknown tag
 } }
  
Ligne 83: Ligne 106:
   digitalWrite(RFIDResetPin,​ LOW);   digitalWrite(RFIDResetPin,​ LOW);
   digitalWrite(RFIDResetPin,​ HIGH);   digitalWrite(RFIDResetPin,​ HIGH);
-  delay(150);+  ​//delay(150); ​//150
 } }
  
Ligne 95: Ligne 118:
   }   }
 } }
 +
 </​code>​ </​code>​
id-12la.1527281878.txt.gz · Dernière modification: 2018/05/25 22:57 par colin