Официальный сайт компании Arduino по адресу arduino.cc
Arduino и RFID
- Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии
Втр, 12/02/2019 - 23:42
Здраствуйте, нужна ваша помощь, у меня создан такой проект то было сделано для одного Ридера, а сейчас их 2 и не могу завтавить с общим кодом, может кто-то опытный подскажет что нужно и куда.
Основной код
#include <SPI.h> #include <Ethernet.h> #include <MFRC522.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> #define SS_PIN 8 #define RST_PIN 9 MFRC522 mfrc522(SS_PIN, RST_PIN); LiquidCrystal_I2C lcd(0x3f,16,2); int in1 = A0; int led0 = 4; int led1 = 2; // зелёный const byte dynPin = 3; byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192, 168, 1, 177); EthernetServer server(80); void setup() { Serial.begin(9600); SPI.begin(); pinMode(led0, OUTPUT); pinMode(led1, OUTPUT); pinMode( dynPin, OUTPUT ); mfrc522.PCD_Init(); Serial.println("Положите вашу карточку к читателю..."); Serial.println(); lcd.begin(); lcd.backlight(); pinMode(in1, OUTPUT); Ethernet.begin(mac, ip); server.begin(); } void loop() { digitalWrite(led0, HIGH); // включить красный EthernetClient client = server.available(); if (client) { Serial.println("new client"); boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); Serial.write(c); if (c == '\n' && currentLineIsBlank) { client.println("<!DOCTYPE HTML><html><head>"); client.println("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"></head><body>"); client.println("<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> "); String content= ""; byte letter; for (byte i = 0; i < mfrc522.uid.size; i++) { content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); content.concat(String(mfrc522.uid.uidByte[i], HEX)); } content.toUpperCase(); if (content.substring(1) == "C0 CA 15 7C") //change here the UID of the card/cards that you want to give access { client.println("1"); } else { client.println("0"); } client.println("</body></html>"); break; } if (c == '\n') { currentLineIsBlank = true; } else if (c != '\r') { currentLineIsBlank = false; } } } delay(1); client.stop(); Serial.println("client disconnected"); } if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } if ( ! mfrc522.PICC_ReadCardSerial()) { return; } //Show UID on serial monitor Serial.print("UID tag :"); String content= ""; byte letter; for (byte i = 0; i < mfrc522.uid.size; i++) { Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); Serial.print(mfrc522.uid.uidByte[i], HEX); content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); content.concat(String(mfrc522.uid.uidByte[i], HEX)); } Serial.println(); Serial.print("Message : "); content.toUpperCase(); if (content.substring(1) == "C0 CA 15 7C") //change here the UID of the card/cards that you want to give access { digitalWrite(in1, HIGH); // Включаем реле tone( dynPin, 200 ); digitalWrite(led1, HIGH); // включить зелёный delay(2000); digitalWrite(led1, LOW); // выключаем зелёный tone( dynPin, 200 ); noTone( dynPin ); lcd.setCursor(0,0); lcd.print("Open"); lcd.setCursor(0,1); lcd.print("Nikolay Antonov"); delay(2000); digitalWrite(in1, LOW); // Включаем реле lcd.clear(); } else if (content.substring(1) == "D6 32 E5 1E") { digitalWrite(in1, HIGH); // Включаем реле tone( dynPin, 200 ); digitalWrite(led1, HIGH); // включить зелёный delay(2000); digitalWrite(led1, LOW); // выключаем зелёный tone( dynPin, 200 ); noTone( dynPin ); lcd.setCursor(0,0); lcd.print("Open"); lcd.setCursor(0,1); lcd.print("Vasia Pupkin"); delay(2000); digitalWrite(in1, LOW); // Включаем реле lcd.clear(); } else { Serial.println("Блокирован"); digitalWrite(led0, HIGH); // включил красный delay(500); // пауза 1-секунда digitalWrite(led0, LOW); // отключил красный tone( dynPin, 200 ); delay( 200 ); noTone( dynPin ); tone( dynPin, 200 ); delay( 100 ); noTone( dynPin ); lcd.setCursor(0,0); lcd.print("Closed"); lcd.setCursor(0,1); lcd.print("Key is unknown"); delay(2000); lcd.clear(); } }
Для двух ридеров
#include <SPI.h> #include <MFRC522.h> #define RST_PIN 9 // Configurable, see typical pin layout above #define SS_1_PIN 7 // 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 NR_OF_READERS 2 byte ssPins[] = {SS_1_PIN, SS_2_PIN}; MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance. /** * 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 } } /** * 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:")); dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size); Serial.println(); } } } /** * Helper routine to dump a byte array as hex values to Serial. */ void dump_byte_array(byte *buffer, byte bufferSize) { for (byte i = 0; i < bufferSize; i++) { Serial.print(buffer[i] < 0x10 ? " 0" : " "); Serial.print(buffer[i], HEX); } }
Уважаемый, почитайте про классы и экземпляры класса. В Вашем случае - строка 12.