Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <MFRC522.h>
- #define RST_PIN 9 // Configurable, see typical pin layout above
- #define SS_1_PIN 10 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
- #define SS_2_PIN 8 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1
- #define SS_3_PIN 7
- #define SS_4_PIN 2
- #define NR_OF_READERS 4
- String codeRead[4], lastCodes[4];
- String correctCodes[5] = {"abcd" , "efgh" , "ijkl" , "mnop" , "qrst"};
- byte ssPins[] = {SS_1_PIN, SS_2_PIN, SS_3_PIN, SS_4_PIN};
- MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
- boolean wasChanged = false;
- /**
- Initialize.
- */
- void setup() {
- Serial.begin(9600); // Initialize serial communications with the PC
- while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
- SPI.begin(); // Init SPI bus
- for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
- mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
- Serial.print(F("Reader "));
- Serial.print(reader);
- Serial.print(F(": "));
- mfrc522[reader].PCD_DumpVersionToSerial();
- }
- }
- /**
- Main loop.
- */
- void loop() {
- for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
- // Look for new cards
- if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
- Serial.print(F("Reader "));
- Serial.print(reader);
- // Show some details of the PICC (that is: the tag/card)
- Serial.print(F(": Card UID:"));
- codeRead[reader] = "";
- for (byte i = 0; i < mfrc522[reader].uid.size; i++) {
- if (mfrc522[reader].uid.uidByte[i] < 10) codeRead[reader] += " 00" ;
- else if (mfrc522[reader].uid.uidByte[i] < 100) codeRead[reader] += " 0";
- else codeRead[reader] += " ";
- codeRead[reader] += String(mfrc522[reader].uid.uidByte[i]);
- }
- Serial.println(reader);
- Serial.println(codeRead[reader]);
- if (lastCodes[reader] != codeRead[reader]) {
- lastCodes[reader] = codeRead[reader];
- wasChanged = true;
- }
- // Halt PICC
- mfrc522[reader].PICC_HaltA();
- // Stop encryption on PCD
- mfrc522[reader].PCD_StopCrypto1();
- } //if (mfrc522[reader].PICC_IsNewC
- delay(100);
- } //for(uint8_t reader
- int correct = 0;
- if (wasChanged) {
- for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
- if (lastCodes[reader] == correctCodes[reader]) correct++;
- }
- Serial.print("You have: ");
- Serial.print(correct);
- Serial.println( " correct tags");
- if (correct == 4) {
- tone(6, 4000);
- digitalWrite(13, HIGH);
- delay(1000);
- noTone(6);
- scramble();
- }
- }
- wasChanged = false;
- }
- void scramble() {
- String tmp;
- for (int i = 0; i < 5; i++) {
- tmp = correctCodes[i];
- correctCodes[i] = correctCodes[i];
- correctCodes[i + 1] = tmp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement