Last active
March 23, 2020 22:48
-
-
Save ypelletier/fd131c2ce05240a944b7fb2c931a4120 to your computer and use it in GitHub Desktop.
Exemple d'utilisation de la bibliothèque MFRC522 par Miguel Balboa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************************* | |
RFID LEDs | |
Exemple d'utilisation de la bibliothèque MFRC522 par Miguel Balboa | |
Lorsque le tag RFID est accepté, une LED verte s'allume pendant 3 secondes | |
Lorsque le tag RFID est refusé, une LED rougeo s'allume pendant 3 secondes | |
Pour plus de détails: | |
https://electroniqueamateur.blogspot.com/2017/04/module-rfid-rc522-et-arduino.html | |
***********************************************************************************/ | |
#include <SPI.h> | |
#include <MFRC522.h> | |
// copier ici le résultat du sketch "lectureUID.ino": | |
const byte bonUID[4] = {144, 207, 148, 117}; | |
const int pinLEDVerte = 7; // LED verte | |
const int pinLEDRouge = 6; // LED rouge | |
const int pinRST = 9; // pin RST du module RC522 | |
const int pinSDA = 10; // pin SDA du module RC522 | |
MFRC522 rfid(pinSDA, pinRST); | |
void setup() | |
{ | |
SPI.begin(); | |
rfid.PCD_Init(); | |
pinMode(pinLEDVerte, OUTPUT); | |
pinMode(pinLEDRouge, OUTPUT); | |
} | |
void loop() | |
{ | |
int refus = 0; // quand cette variable n'est pas nulle, c'est que le code est refusé | |
if (rfid.PICC_IsNewCardPresent()) // on a dédecté un tag | |
{ | |
if (rfid.PICC_ReadCardSerial()) // on a lu avec succès son contenu | |
{ | |
for (byte i = 0; i < rfid.uid.size; i++) // comparaison avec le bon UID | |
{ | |
if (rfid.uid.uidByte[i] != bonUID[i]) { | |
refus++; | |
} | |
} | |
if (refus == 0) // UID accepté | |
{ | |
// on allume la LED verte pendant trois secondes | |
digitalWrite(pinLEDVerte, HIGH); | |
delay(3000); | |
digitalWrite(pinLEDVerte, LOW); | |
} | |
else { // UID refusé | |
// on allume la LED rouge pendant trois secondes | |
digitalWrite(pinLEDRouge, HIGH); | |
delay(3000); | |
digitalWrite(pinLEDRouge, LOW); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment