Skip to content

Instantly share code, notes, and snippets.

@prasertsakd
Created January 8, 2017 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prasertsakd/bf5b86f64a4cd7780cf42181f6b7a720 to your computer and use it in GitHub Desktop.
Save prasertsakd/bf5b86f64a4cd7780cf42181f6b7a720 to your computer and use it in GitHub Desktop.
#include <PN532.h>
#include "Keyboard.h"
//#define SCK 13
//#define MOSI 11
//#define SS 10
//#define MISO 12
#define SCK 15
#define MOSI 16
#define SS 10
#define MISO 14
PN532 nfc(SCK, MISO, MOSI, SS);
unsigned long previousMillis = 0;
uint32_t count;
void setup(void) {
Serial.begin(115200);
Keyboard.begin();
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
while (1){
Serial.println("Didn't find PN53x board");
delay(1000);
}
}
// Got ok data, print it out!
// Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
// Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
// Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
// Serial.print("Supports "); Serial.println(versiondata & 0xFF, HEX);
// configure board to read RFID tags and cards
nfc.SAMConfig();
}
void loop(void) {
uint32_t id;
// look for MiFare type cards
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 20) {
id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);
if (id != 0) {
//Serial.println();
Serial.print(count);Serial.print(" Read card #"); Serial.println(id);
Keyboard.print("[");Keyboard.print(id);Keyboard.print("]");
previousMillis = currentMillis;
count++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment