UNO完整版代码


#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();
  }
  
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值