#include #include #include #define BUZZER A0 PN532_HSU pn532hsu(Serial1); PN532 nfc(pn532hsu); Servo myservo; // create servo object to control a servo String NFC_Key_1 = "xxxxx"; String NFC_Key_2 = "xxxxx"; int led = 13; //*******************fonction lecture de tag String fct_lecture(){ String Received; boolean success; uint8_t IdReceived[] = { 0, 0, 0, 0, 0, 0, 0 }; uint8_t Id_Length; if (success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &IdReceived[0],&Id_Length)){ for (uint8_t i=0; i < Id_Length; i++) Received += String(IdReceived[i], HEX); return(Received); } else return("NULL"); } //*******************fonction open void fct_open(){ myservo.write(180); delay(8000); myservo.write(0); } void setup(void) { Serial.begin(115200); nfc.begin(); nfc.setPassiveActivationRetries(0xFF); nfc.SAMConfig(); myservo.attach(12); myservo.write(0); Serial.println("KeyDuino BOX is ready, please scan a NFC tag"); pinMode(BUZZER, OUTPUT); pinMode(led, OUTPUT); digitalWrite(led, HIGH); } void loop(void) { String Received; Received=fct_lecture(); if (Received != "NULL"){ Serial.println(Received); if (Received == NFC_Key_1 || Received == NFC_Key_2) { fct_open(); digitalWrite(led, LOW); delay(500); digitalWrite(led, HIGH); } else { digitalWrite(BUZZER, HIGH); delay(100); digitalWrite(BUZZER, LOW); delay(100); digitalWrite(BUZZER, HIGH); delay(100); digitalWrite(BUZZER, LOW); } } }