1 changed files with 124 additions and 0 deletions
@ -0,0 +1,124 @@ |
|||
/*
|
|||
* Signal Pin Pin Pin |
|||
* Arduino Uno Arduino Mega MFRC522 board |
|||
* ------------------------------------------------------------ |
|||
* Reset 9 5 RST |
|||
* SPI SS 10 53 SDA |
|||
* SPI MOSI 11 51 MOSI |
|||
* SPI MISO 12 50 MISO |
|||
* SPI SCK 13 52 SCK |
|||
*/ |
|||
|
|||
#include <SPI.h> |
|||
#include <MFRC522.h> |
|||
|
|||
#define SS_PIN 10 |
|||
#define RST_PIN 9 |
|||
|
|||
#define LED_BOX 6 |
|||
#define LED_PLATFORMS 5 |
|||
|
|||
int LedStatus=0; |
|||
bool onBox = false; |
|||
|
|||
MFRC522 mfrc522(SS_PIN, RST_PIN); |
|||
|
|||
long previousMillis = 0; |
|||
long interval = 10; |
|||
|
|||
String uid_s; |
|||
String uid_old = ""; |
|||
|
|||
String uidRFID[] = {"b278d53b","8084d53b","d683d53b","01020304","7b83d53b","427ad53b"}; |
|||
|
|||
void setup() { |
|||
|
|||
Serial.begin(9600); // Initialize serial communications with the PC
|
|||
SPI.begin(); // Init SPI bus
|
|||
mfrc522.PCD_Init(); // Init MFRC522 card
|
|||
//Serial.println("In attesa di lettura...");
|
|||
|
|||
pinMode(LED_BOX, OUTPUT); |
|||
pinMode(LED_PLATFORMS, OUTPUT); |
|||
|
|||
} |
|||
|
|||
void loop() { |
|||
|
|||
unsigned long currentMillis = millis(); |
|||
|
|||
if(currentMillis - previousMillis > interval) { |
|||
previousMillis = currentMillis; |
|||
|
|||
// Look for new cards
|
|||
if ( ! mfrc522.PICC_IsNewCardPresent()) { |
|||
|
|||
if(LedStatus==200){ |
|||
for(LedStatus=200;LedStatus>=0;LedStatus--){ |
|||
analogWrite(LED_BOX,LedStatus); |
|||
analogWrite(LED_PLATFORMS,200-LedStatus); |
|||
delay(10); |
|||
} |
|||
onBox = false; |
|||
} |
|||
return; |
|||
} |
|||
|
|||
// Select one of the cards
|
|||
if ( ! mfrc522.PICC_ReadCardSerial()) { |
|||
return; |
|||
} |
|||
|
|||
if(LedStatus<200){ |
|||
for(LedStatus=0;LedStatus<200;LedStatus++){ |
|||
analogWrite(LED_BOX,LedStatus); |
|||
analogWrite(LED_PLATFORMS,200-LedStatus); |
|||
delay(10); |
|||
} |
|||
onBox = true; |
|||
} |
|||
|
|||
uid_s = ""; |
|||
|
|||
if (!mfrc522.PICC_IsNewCardPresent() && !mfrc522.PICC_ReadCardSerial()) { |
|||
|
|||
for (byte i = 0; i < mfrc522.uid.size; i++) { |
|||
|
|||
String uid_a = String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : ""); |
|||
String uid_b = String(mfrc522.uid.uidByte[i], HEX); |
|||
|
|||
uid_s = uid_s+uid_a+uid_b; |
|||
} |
|||
} |
|||
|
|||
if(uid_s != uid_old || onBox){ |
|||
onBox = false; |
|||
uid_old = uid_s; |
|||
//Serial.print("RFID UID rivelato --> ");
|
|||
//Serial.println(uid_s);
|
|||
//Serial.println("");
|
|||
|
|||
boolean control = false; |
|||
for (int i = 0; i < sizeof(uidRFID)/sizeof(String); i++){ |
|||
|
|||
if(uidRFID[i] == uid_s){ |
|||
|
|||
Serial.print("ID"); |
|||
Serial.print("\t"); |
|||
Serial.println(i); |
|||
control = true; |
|||
break; |
|||
|
|||
} |
|||
} |
|||
|
|||
if(!control){ |
|||
//Serial.println("Accesso vietato");
|
|||
delay(1000); |
|||
} |
|||
|
|||
//Serial.println();
|
|||
//Serial.println("In attesa di lettura...");
|
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue