#include <LiquidCrystal.h>
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9
MFRC522 mfrc522(SDA, RST_PIN); // 创建MFRC实例
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
pinMode(8,OUTPUT);
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.println("系统开启,请将你的卡片放置感应区...");
}
void loop() {
String content= "";
lcd.setCursor(0,0);
lcd.print("Welcome!");
lcd.print(content);
// 寻找新卡
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//显示卡号 b6a5eebc 182165238188
//Serial.print("UID tag :");
for (byte i = 0; i < mfrc522.uid.size; i++)
{
//Serial.println(mfrc522.uid.uidByte[i]);
//Serial.print(mfrc522.uid.uidByte[i], HEX);
content+=mfrc522.uid.uidByte[i];
}
if(content!="")
{
lcd.setCursor(0,0);
lcd.print("Your ID:");
lcd.setCursor(0,1);
lcd.print(content);
Serial.println(content);
digitalWrite(8,HIGH);
delay(300);
digitalWrite(8,LOW);
delay(2000);
content= "";
lcd.clear();
}
}
UNO完整版代码
猜你喜欢
转载自blog.csdn.net/Tony6666_/article/details/97621742
今日推荐
周排行