zamek

admin
Site Admin
Posty: 21
Rejestracja: sob lut 07, 2015 4:03 pm

zamek

Postautor: admin » pn cze 17, 2019 6:25 pm

#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
int buzzPin = 3;
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup()
{
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
Serial.println("reader...");
Serial.println();
pinMode (6, OUTPUT);
pinMode (7, OUTPUT);
digitalWrite(7,LOW);
digitalWrite(6, LOW);
}
void loop()
{
String content= "";


// Scan for cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Selects a card
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//show UID on serial monitor
Serial.print("UID tag :");

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) == "54 17 CD 73") || (content.substring(1) == "BD 2C E8 24") ) //change the codes with the cards codes found after scanning in serial monitor
{

Serial.println("otwarte");
analogWrite(3,20);
delay(100);
analogWrite(3,0);
Serial.println();
digitalWrite (7,HIGH);
delay(3000);
digitalWrite (7,LOW);
delay(3000);

}

else {
Serial.println("zla karta");
analogWrite(3,20);
delay(500);
analogWrite(3,0);
digitalWrite (6,HIGH);
delay(3000);
digitalWrite (6, LOW);
delay(3000);

}
}