C 使用RFID卡授予访问权限
我的arduino计划有问题。我使用RFID阅读器扫描卡片(这部分工作完美无瑕)。我希望程序允许使用一些按钮访问(老实说没关系)。使用验证卡的用户可以使用这些功能,直到再次扫描卡为止。我删除了代码中一些不必要的部分C 使用RFID卡授予访问权限,c,arduino,C,Arduino,我的arduino计划有问题。我使用RFID阅读器扫描卡片(这部分工作完美无瑕)。我希望程序允许使用一些按钮访问(老实说没关系)。使用验证卡的用户可以使用这些功能,直到再次扫描卡为止。我删除了代码中一些不必要的部分 #include <SPI.h> #include <MFRC522.h> String read_rfid; String ok_rfid_1="a3f90f7"; //ID of the verified CARD const int buzzer=8;
#include <SPI.h>
#include <MFRC522.h>
String read_rfid;
String ok_rfid_1="a3f90f7"; //ID of the verified CARD
const int buzzer=8; //Buzzer
const int redLed=7;
const int greenLed=6;
const int yellowLed=5;
byte access=false; //
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
}
/*
* Helper routine to dump a byte array as hex values to Serial.
*/
void dump_byte_array(byte *buffer, byte bufferSize) {
read_rfid="";
for (byte i = 0; i < bufferSize; i++) {
read_rfid=read_rfid + String(buffer[i], HEX);
}
}
void granted() { } //it lights up the green led
void denied() { } //it lights up the red led
void login() {
if (read_rfid==ok_rfid_1) {
granted();
access=true;
} else {
denied();
}
delay(1000);
}
void logout() {
if (read_rfid==ok_rfid_1 && access==1) {
access=false;
Serial.println("Logout ");
}
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
return;
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
return;
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println(read_rfid);
login();
while(access==true)
{logout();};
}
#包括
#包括
字符串读取;
字符串ok_rfid_1=“a3f90f7”//已验证卡的ID
常数int蜂鸣器=8//蜂鸣器
常数int redLed=7;
常数int绿色LED=6;
常数int黄色LED=5;
字节访问=false;//
无效设置(){
Serial.begin(9600);//初始化与PC的串行通信
SPI.begin();//初始化SPI总线
mfrc522.PCD_Init();//初始化mfrc522卡
}
/*
*Helper例程将字节数组作为十六进制值转储到串行。
*/
无效转储字节数组(字节*缓冲区,字节缓冲区大小){
读_rfid=“”;
for(字节i=0;i
登录部分工作正常,但会自动注销。正如我观察到的,问题可能是
if(read\u rfid==ok\u rfid\u 1&&access==1)
总是正确的,因为read\u rfid
不会改变。你有什么办法来解决我的难题吗?access
已经是一个布尔值了,把access==1
改为access
和while(access==true)->while(access)
。你有while(access==true){logout();}代码>在这里,但似乎没有任何代码可以在任何地方读取新数据,而这些代码可以更改ok\u rfid\u 1
或access
access
已经是一个布尔值,将access==1
更改为仅仅access
和while(access==true)->while(access)
;代码>此处,但似乎没有任何代码可以读取任何可能更改的新数据ok\u rfid\u 1
或access