Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <MFRC522.h>
- #define RST_PIN D4
- #define SS_PIN D8
- MFRC522 mfrc522(SS_PIN, RST_PIN);
- void setupRfid() {
- SPI.begin();
- mfrc522.PCD_Init();
- }
- String processRfid() {
- String rfidData = "";
- if ( ! mfrc522.PICC_IsNewCardPresent())
- return "";
- if ( ! mfrc522.PICC_ReadCardSerial())
- return "";
- rfidData = rfidDataToString(mfrc522.uid.uidByte, mfrc522.uid.size);
- return rfidData;
- }
- String rfidDataToString(byte *buffer, byte bufferSize) {
- String temp = "";
- for (byte i = 0; i < bufferSize; i++) {
- temp += buffer[i] < 0x10 ? "0" : "";
- temp += String(buffer[i], HEX);
- }
- return temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment