|
楼主 |
发表于 2021-6-11 01:40
|
显示全部楼层
#include"rfid.h"
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27,16,2);
RFID rfid; //create a variable type of RFID
#define relayPin 8 //relay module attach to pin8
uchar serNum[5]; // array to store your ID
void setup()
{
lcd.init(); //initialize lcd
lcd.backlight(); //turn on the backlight
Serial.begin(9600);
rfid.begin(7, 5, 4, 3, 6, 2);//rfid.begin(IRQ_PIN,SCK_PIN,MOSI_PIN,MISO_PIN,NSS_PIN,RST_PIN)
delay(100);
rfid.init(); //initialize the RFID
pinMode(relayPin, OUTPUT); //set relayPin as OUTPUT
digitalWrite(relayPin,HIGH); //and high level
//Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print(" Welcome! "); //print" Welcome! "
delay(2000);//delay 2s
}
void loop()
{
uchar status;
uchar str[MAX_LEN];
status = rfid.request(PICC_REQIDL, str);
if (status != MI_OK)
{
return;
}
rfid.showCardType(str);
status = rfid.anticoll(str);
if (status == MI_OK)
{
//Serial.print("The card's number is: ");
lcd.setCursor(0,0);
lcd.print(" ID: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);//show the card ID
// Serial.println();
//1号大宝贝的卡
// 显示你饭卡的card ID 8F3D0329
uchar* id = serNum;
if( id[0]==0xDA && id[1]==0x5C && id[2]==0x20 && id[3]==0x86 )
{
digitalWrite(relayPin,LOW);
lcd.setCursor(0,1);
lcd.print(" Hello dou ");
delay(2000);
lcd.clear();
digitalWrite(relayPin,HIGH);
}
else if( id[0]==0x8B && id[1]==0x95 && id[2]==0xC5 && id[3]==0x22 )
{
digitalWrite(relayPin,LOW);
lcd.setCursor(0,1);
lcd.print(" Hello Chen ");
delay(2000);
lcd.clear();
digitalWrite(relayPin,HIGH);
}
else
{
//Serial.println("Hello unkown guy!");
lcd.setCursor(0,1);
lcd.print("Hello bye");
delay(2000);
lcd.clear();
}
}
lcd.setCursor(0,0);
lcd.print(" Welcome! ");
delay(2000);
rfid.halt(); //command the card into sleep mode
} |
|