bonjour
bon j'ai fouillé pour voir comment sortir de la fonction void loop....j'ai bien lu et j'ai essayé plusieurs choses mais je n'arrive pas à avoir le résultat escompté.
j'ai un lecteur rfid. je voudrais qu'à la première lecture au setup si le tag est bon qu'il continue le programme sinon demande de passage du badge tant que le tag est invalide.
dans la boucle loop, si une lecture est faite, sortie de la boucle et recommencement du programme.
j'essaie de faire en sorte que le lecteur rfid serve de on off en gros.
j'arrive à lire et à afficher on off en utilisant un flag booléen mais pas à avoir le comportement voulu. j'ai utilisé exit mais je vois que c'est inadapté.
Qu'est ce que je peux utiliser...comme piste?
merci
#include <SoftwareSerial.h>
boolean stop = false;
//initialise RFID .
const int RFID_RX_Pin = 0; // the TX pin
String Parsed_Tag_ID, Stored_Tag_ID, Authentified_Tag_ID="01001BB90DAE";
char c;
SoftwareSerial RFID(RFID_RX_Pin , 1); // RX, TX for serial communication on any digital pins.
// RX port : 0 -- TX port :1)
boolean CheckSum_Tag_ID(String Tag_ID) {
boolean res = false;
unsigned int b1,b2,b3,b4,b5,checksum;
//Convert Tag_ID String into array of chars in order to use sscanf
char charBuf[13];
Tag_ID.toCharArray(charBuf, 13);
sscanf(charBuf , "%2x%2x%2x%2x%2x%2x", &b1, &b2, &b3, &b4, &b5, &checksum);
//Control
if ( (b1 ^ b2 ^ b3 ^ b4 ^ b5) == checksum ) {
return true;
} else {
Serial.println("Repasser badge");
return false;
}
}
void lecture () {
Stored_Tag_ID="";
//Read RFID TAG
RFID.listen(); //Enables the selected software serial port to listen.
//Only one software serial port can listen at a time; data that arrives for other ports will be discarded.
//Any data already received is discarded during the call to listen() (unless the given instance is already listening).
if ( RFID.isListening() ) { //Tests to see if requested software serial port is actively listening.
while( RFID.available() > 0 ){ //Get the number of bytes (characters) available for reading from a software serial port.
//This is data that's already arrived and stored in the serial receive buffer.
c=RFID.read(); //Reads one char/byte at a time
Parsed_Tag_ID += c; //Store the char into the Parsed_Tag_ID string
if ( Parsed_Tag_ID.length() == 14 ) { //The TAG ID has 14 chars in total
if ( (Parsed_Tag_ID[0]==2) && (Parsed_Tag_ID[13]==3) ) { //If the first char is 2 and the last one is 3 then ...
Parsed_Tag_ID = Parsed_Tag_ID.substring(1,13); //Delete the 1st and the 13th (last) char
if ( CheckSum_Tag_ID(Parsed_Tag_ID) == true ) { //Validate the Parsed Tag Id
Stored_Tag_ID=Parsed_Tag_ID;
}
}
Parsed_Tag_ID="";
stop=true;
}//read the 14 chars ok
}
}
//Read the RFID TAG END
}
void setup() {
Serial.begin(9600);
//Setup RFID serial
RFID.begin(9600);
lecture();
if ( Stored_Tag_ID!= Authentified_Tag_ID ){
Serial.println("non authorisé");
exit;}
else {
Serial.println("on");
}
}
void loop() {
lecture();
// use the Stored Tag ID ...
if (stop==true ) {
Serial.println("OFF '" + Stored_Tag_ID + "'");
exit;
}
Serial.println("blabla");
delay(5000);
}