代码部分

#include <rfid.h>                 //射频模块
#include <LiquidCrystal_I2C.h>    //I²C接口
#include <Wire.h>                 //LCD
#include <Servo.h>                //舵机

LiquidCrystal_I2C lcd(0x27, 16, 2); //0x27:I2C接口的地址 16,2:可显示16*2的字符串
Servo myservo;                    //创建一个伺服对象"myservo"
RFID rfid;                        //创建一个可变类型的RFID

uchar serNum[5];                  //创建一个数组来储存ID

void setup()
{
lcd.init();                     //初始化 LCD
lcd.backlight();                //打开LCD的背光
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();                    //初始化 RFID
lcd.setCursor(0, 0);            //把光标定在显示屏的第0列第0行
lcd.print("    Welcome!    ");  //在LCD"    Welcome!    "
lcd.setCursor(0, 1);
lcd.print("    !6-1322!    ");
myservo.attach(8);              //说明8号针脚的舵机连接到伺服对象上
myservo.write(0);               //舵机归位0°
delay(2000);                    //delay 2s
}

void loop()
{
uchar status;
uchar str[MAX_LEN];
//检测是否有ID卡,返回ID卡的类型
status = rfid.request(PICC_REQIDL, str);
if (status != MI_OK)            //检测是否有卡
{
return;
}
//显示卡的类型
rfid.showCardType(str);
//防止冲突,返回4字节的序列号的卡片
status = rfid.anticoll(str);

if (status == MI_OK)

{

Serial.print("The card's number is: ");
lcd.setCursor(0, 0);          //LCD的坐标:0列,0行
lcd.print(" ID: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);      //show the card ID
Serial.println();
//确认IC卡的ID是否为 3AA9EA0B
uchar* id = serNum;
if (id[0] == 0x99 && id[1] == 0x59 && id[2] == 0x48 && id[3] == 0xB3)
{ //该卡号可以更改为自己的IC卡号,包括校园卡等
myservo.write(180);         //舵机旋转至180°
Serial.println("Hello Arduino!");
lcd.setCursor(0, 1);        //显示的坐标:0列,1行
lcd.print(" Hello TZP! ");
delay(4000);
lcd.clear();                //LCD清屏
myservo.write(0);
}
else
{ //若卡号与上述不符
Serial.println("Fuck you guys!");
lcd.setCursor(0, 1);
lcd.print("Fuck you guys");
delay(2000);
lcd.clear();
}
}

if (status == MI_OK)
{
Serial.print("The card's number is: ");
lcd.setCursor(0, 0);          //LCD的坐标:0列,0行
lcd.print(" ID: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);      //show the card ID
Serial.println();
//确认IC卡的ID是否为 3AA9EA0B
uchar* id = serNum;
if (id[0] == 0xD6 && id[1] == 0x53 && id[2] == 0xF4 && id[3] == 0xFF)
{ //该卡号可以更改为自己的IC卡号,包括校园卡等
myservo.write(180);         //舵机旋转至180°
Serial.println("Hello Arduino!");
lcd.setCursor(0, 1);        //显示的坐标:0列,1行
lcd.print(" Hello WMF! ");
delay(4000);
lcd.clear();                //LCD清屏
myservo.write(0);
}
else
{ //若卡号与上述不符
Serial.println("Fuck you guys!");
lcd.setCursor(0, 1);
lcd.print("Fuck you guys");
delay(2000);
lcd.clear();
}
}
/*
if (status == MI_OK)
{
Serial.print("The card's number is: ");
lcd.setCursor(0, 0);          //LCD的坐标:0列,0行
lcd.print(" ID: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);      //show the card ID
Serial.println();
//确认IC卡的ID是否为 3AA9EA0B
uchar* id = serNum;
if (id[0] == 0x3A && id[1] == 0xA9 && id[2] == 0xEA && id[3] == 0x0B)
{ //该卡号可以更改为自己的IC卡号,包括校园卡等
myservo.write(180);         //舵机旋转至180°
Serial.println("Hello Arduino!");
lcd.setCursor(0, 1);        //显示的坐标:0列,1行
lcd.print(" Hello Arduino! ");
delay(2000);
lcd.clear();                //LCD清屏
myservo.write(0);
}
else
{ //若卡号与上述不符
Serial.println("Fuck you guys!");
lcd.setCursor(0, 1);
lcd.print("Fuck you guys");
delay(2000);
lcd.clear();
}
}
if (status == MI_OK)
{
Serial.print("The card's number is: ");
lcd.setCursor(0, 0);          //LCD的坐标:0列,0行
lcd.print(" ID: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);      //show the card ID
Serial.println();
//确认IC卡的ID是否为 3AA9EA0B
uchar* id = serNum;
if (id[0] == 0x3A && id[1] == 0xA9 && id[2] == 0xEA && id[3] == 0x0B)
{ //该卡号可以更改为自己的IC卡号,包括校园卡等
myservo.write(180);         //舵机旋转至180°
Serial.println("Hello Arduino!");
lcd.setCursor(0, 1);        //显示的坐标:0列,1行
lcd.print(" Hello Arduino! ");
delay(2000);
lcd.clear();                //LCD清屏
myservo.write(0);
}
else
{ //若卡号与上述不符
Serial.println("Fuck you guys!");
lcd.setCursor(0, 1);
lcd.print("Fuck you guys");
delay(2000);
lcd.clear();
}
}
if (status == MI_OK)
{
Serial.print("The card's number is: ");
lcd.setCursor(0, 0);          //LCD的坐标:0列,0行
lcd.print(" ID: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);      //show the card ID
Serial.println();
//确认IC卡的ID是否为 3AA9EA0B
uchar* id = serNum;
if (id[0] == 0x3A && id[1] == 0xA9 && id[2] == 0xEA && id[3] == 0x0B)
{ //该卡号可以更改为自己的IC卡号,包括校园卡等
myservo.write(180);         //舵机旋转至180°
Serial.println("Hello Arduino!");
lcd.setCursor(0, 1);        //显示的坐标:0列,1行
lcd.print(" Hello Arduino! ");
delay(2000);
lcd.clear();                //LCD清屏
myservo.write(0);
}
else
{ //若卡号与上述不符
Serial.println("Fuck you guys!");
lcd.setCursor(0, 1);
lcd.print("Fuck you guys");
delay(2000);
lcd.clear();
}
}
if (status == MI_OK)
{
Serial.print("The card's number is: ");
lcd.setCursor(0, 0);          //LCD的坐标:0列,0行
lcd.print(" ID: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);      //show the card ID
Serial.println();
//确认IC卡的ID是否为 3AA9EA0B
uchar* id = serNum;
if (id[0] == 0x3A && id[1] == 0xA9 && id[2] == 0xEA && id[3] == 0x0B)
{ //该卡号可以更改为自己的IC卡号,包括校园卡等
myservo.write(180);         //舵机旋转至180°
Serial.println("Hello Arduino!");
lcd.setCursor(0, 1);        //显示的坐标:0列,1行
lcd.print(" Hello Arduino! ");
delay(2000);
lcd.clear();                //LCD清屏
myservo.write(0);
}
else
{ //若卡号与上述不符
Serial.println("Fuck you guys!");
lcd.setCursor(0, 1);
lcd.print("Fuck you guys");
delay(2000);
lcd.clear();
}
}

if (status == MI_OK)

{
Serial.print("The card's number is: ");
lcd.setCursor(0, 0);          //LCD的坐标:0列,0行
lcd.print(" ID: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);      //show the card ID
Serial.println();
//确认IC卡的ID是否为 3AA9EA0B
uchar* id = serNum;
if (id[0] == 0x3A && id[1] == 0xA9 && id[2] == 0xEA && id[3] == 0x0B)
{ //该卡号可以更改为自己的IC卡号,包括校园卡等
myservo.write(180);         //舵机旋转至180°
Serial.println("Hello Arduino!");
lcd.setCursor(0, 1);        //显示的坐标:0列,1行
lcd.print(" Hello Arduino! ");
delay(2000);
lcd.clear();                //LCD清屏
myservo.write(0);
}
else
{ //若卡号与上述不符
Serial.println("Fuck you guys!");
lcd.setCursor(0, 1);
lcd.print("Fuck you guys");
delay(2000);
lcd.clear();
}
}
if (status == MI_OK)
{
Serial.print("The card's number is: ");
lcd.setCursor(0, 0);          //LCD的坐标:0列,0行
lcd.print(" ID: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);      //show the card ID
Serial.println();
//确认IC卡的ID是否为 3AA9EA0B
uchar* id = serNum;
if (id[0] == 0x3A && id[1] == 0xA9 && id[2] == 0xEA && id[3] == 0x0B)
{ //该卡号可以更改为自己的IC卡号,包括校园卡等
myservo.write(180);         //舵机旋转至180°
Serial.println("Hello Arduino!");
lcd.setCursor(0, 1);        //显示的坐标:0列,1行
lcd.print(" Hello Arduino! ");
delay(2000);
lcd.clear();                //LCD清屏
myservo.write(0);
}
else
{ //若卡号与上述不符
Serial.println("Fuck you guys!");
lcd.setCursor(0, 1);
lcd.print("Fuck you guys");
delay(2000);
lcd.clear();
}
}
if (status == MI_OK)
{
Serial.print("The card's number is: ");
lcd.setCursor(0, 0);          //LCD的坐标:0列,0行
lcd.print(" ID: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);      //show the card ID
Serial.println();
//确认IC卡的ID是否为 3AA9EA0B
uchar* id = serNum;
if (id[0] == 0x3A && id[1] == 0xA9 && id[2] == 0xEA && id[3] == 0x0B)
{ //该卡号可以更改为自己的IC卡号,包括校园卡等
myservo.write(180);         //舵机旋转至180°
Serial.println("Hello Arduino!");
lcd.setCursor(0, 1);        //显示的坐标:0列,1行
lcd.print(" Hello Arduino! ");
delay(2000);
lcd.clear();                //LCD清屏
myservo.write(0);
}
else
{ //若卡号与上述不符
Serial.println("Fuck you guys!");
lcd.setCursor(0, 1);
lcd.print("Fuck you guys");
delay(2000);
lcd.clear();
}
}
if (status == MI_OK)
{
Serial.print("The card's number is: ");
lcd.setCursor(0, 0);          //LCD的坐标:0列,0行
lcd.print(" ID: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);      //show the card ID
Serial.println();
//确认IC卡的ID是否为 3AA9EA0B
uchar* id = serNum;
if (id[0] == 0x3A && id[1] == 0xA9 && id[2] == 0xEA && id[3] == 0x0B)
{ //该卡号可以更改为自己的IC卡号,包括校园卡等
myservo.write(180);         //舵机旋转至180°
Serial.println("Hello Arduino!");
lcd.setCursor(0, 1);        //显示的坐标:0列,1行
lcd.print(" Hello Arduino! ");
delay(2000);
lcd.clear();                //LCD清屏
myservo.write(0);
}
else
{ //若卡号与上述不符
Serial.println("Fuck you guys!");
lcd.setCursor(0, 1);
lcd.print("Fuck you guys");
delay(2000);
lcd.clear();
}
}
if (status == MI_OK)
{
Serial.print("The card's number is: ");
lcd.setCursor(0, 0);          //LCD的坐标:0列,0行
lcd.print(" ID: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);      //show the card ID
Serial.println();
//确认IC卡的ID是否为 3AA9EA0B
uchar* id = serNum;
if (id[0] == 0x3A && id[1] == 0xA9 && id[2] == 0xEA && id[3] == 0x0B)
{ //该卡号可以更改为自己的IC卡号,包括校园卡等
myservo.write(180);         //舵机旋转至180°
Serial.println("Hello Arduino!");
lcd.setCursor(0, 1);        //显示的坐标:0列,1行
lcd.print(" Hello Arduino! ");
delay(2000);
lcd.clear();                //LCD清屏
myservo.write(0);
}
else
{ //若卡号与上述不符
Serial.println("Fuck you guys!");
lcd.setCursor(0, 1);
lcd.print("Fuck you guys");
delay(2000);
lcd.clear();
}
}
if (status == MI_OK)
{
Serial.print("The card's number is: ");
lcd.setCursor(0, 0);          //LCD的坐标:0列,0行
lcd.print(" ID: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);      //show the card ID
Serial.println();
//确认IC卡的ID是否为 3AA9EA0B
uchar* id = serNum;
if (id[0] == 0x3A && id[1] == 0xA9 && id[2] == 0xEA && id[3] == 0x0B)
{ //该卡号可以更改为自己的IC卡号,包括校园卡等
myservo.write(180);         //舵机旋转至180°
Serial.println("Hello Arduino!");
lcd.setCursor(0, 1);        //显示的坐标:0列,1行
lcd.print(" Hello Arduino! ");
delay(2000);
lcd.clear();                //LCD清屏
myservo.write(0);
}
else
{ //若卡号与上述不符
Serial.println("Fuck you guys");
lcd.setCursor(0, 1);
lcd.print("Fuck you guys");
delay(2000);
lcd.clear();
}
}
*/
lcd.setCursor(0, 0);
lcd.print("    Welcome!    ");
delay(2000);
rfid.halt();                    //让IC卡进入休眠状态、防抖

}
最后修改:2021 年 01 月 23 日 02 : 34 PM
如果觉得我的文章对你有用,请随意赞赏