|
楼主 |
发表于 2016-2-26 11:05:53
|
显示全部楼层
本帖最后由 nepu2015 于 2016-2-26 11:11 编辑
- #include <SPI.h>
- #include <RFID.h>
- #include <Servo.h>
- RFID rfid(10,9); //D10--读卡器MOSI引脚、D5--读卡器RST引脚
- int temp=0;
- Servo myservo;//定义舵机变量名
- void setup()
- {
- Serial.begin(9600);
- SPI.begin();
- rfid.init();
- myservo.attach(8);
- }
- void loop()
- {
- //找卡
- if (rfid.isCard()) {
- Serial.println("Find the card!");
- //读取卡序列号
- if (rfid.readCardSerial()) {
- Serial.print("The card's number is : ");
- Serial.print(rfid.serNum[0],HEX);
- Serial.print(rfid.serNum[1],HEX);
- Serial.print(rfid.serNum[2],HEX);
- Serial.print(rfid.serNum[3],HEX);
- Serial.print(rfid.serNum[4],HEX);
- Serial.println(" ");
-
- if(rfid.serNum[0]==0xA7&&rfid.serNum[1]==0x4C&&rfid.serNum[2]==0xC9)
- {
- temp=1;
- }
- if(rfid.serNum[0]==0xE9&&rfid.serNum[1]==0x6E&&rfid.serNum[2]==0x9C)
- {
- temp=1;
- }
- if(rfid.serNum[0]==0xD7&&rfid.serNum[1]==0xF6&&rfid.serNum[2]==0xAB)
- {
- temp=1;
- }
- /************/
- if(rfid.serNum[0]==0x55&&rfid.serNum[1]==0xE2)
- {
- temp=1;
- }
-
- if(rfid.serNum[0]==0x95&&rfid.serNum[1]==0x18)
- {
- temp=1;
- }
-
- if(rfid.serNum[0]==0x54&&rfid.serNum[1]==0xC2)
- {
- temp=1;
- }
- if(rfid.serNum[0]==0xA5&&rfid.serNum[1]==0x6B)
- {
- temp=1;
- }
-
-
- if(rfid.serNum[0]==0x15&&rfid.serNum[1]==0xCE)
- {
- temp=1;
- }
-
- if(rfid.serNum[0]==0x54&&rfid.serNum[1]==0xC2)
- {
- temp=1;
- }
- if(rfid.serNum[0]==0x25&&rfid.serNum[1]==0x7F)
- {
- temp=1;
- }
-
- if(rfid.serNum[0]==0x75&&rfid.serNum[1]==0xC7)
- {
- temp=1;
- }
- }
- //选卡,可返回卡容量(锁定卡片,防止多数读取),去掉本行将连续读卡
- rfid.selectTag(rfid.serNum);
- }
- if(temp==1)
- {
- myservo.write(30);
- delay(5000);
- myservo.write(90);
- temp=0;
- }
- rfid.halt();
- }
复制代码 代码很简单,就是利用rfid库文件,也不知道这么写对不对,反正不规范就是了 。实在是块熄灯了懒得改了,而且只有一个模块...让我沾上门里面去了.....你能想象坐在门口一个个刷卡的感受么
自己第一次发帖子...补充一下...那个继电器 是过了一天同学才给我带的....唉 实在是猴急哈哈哈
|
|