Untitled
unknown
plain_text
2 years ago
1.8 kB
18
Indexable
// NFC INITIATION
#include <Arduino.h>
#include <NfcAdapter.h>
#include <PN532.h>
#include <PN532_I2C.h>
#include <Wire.h>
PN532_I2C pn532i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532i2c);
// OLED INITIATION
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup(void) {
Serial.begin(115200);
Serial.println("Hello!");
nfc.begin(true);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;)
; // Don't proceed, loop forever
}
Serial.println("Waiting for an ISO14443A card");
display.setCursor(0, 40); // oled display
display.setTextSize(1);
display.setTextColor(WHITE);
display.print("Waiting for NFC Card");
display.display();
}
void loop(void) {
if (nfc.tagPresent()) {
NfcTag tag = nfc.read();
tag.print();
display.clearDisplay();
display.setCursor(10, 0);
display.setTextSize(1);
display.setTextColor(WHITE);
display.printf("UID Length: %d bytes", tag.getUidLength());
if (tag.hasNdefMessage()) {
NdefMessage message = tag.getNdefMessage();
message.print();
display.setCursor(0, 20);
display.setTextSize(1);
display.setTextColor(WHITE);
display.printf("NDEF Message has %d records", message.getRecordCount());
}
// Wait a bit before trying again
Serial.println("\n\nSend a character to scan another tag!");
Serial.flush();
while (!Serial.available())
;
while (Serial.available()) {
Serial.read();
}
Serial.flush();
}
}
Editor is loading...
Leave a Comment