commit
83909f0e83
1 changed files with 96 additions and 0 deletions
@ -0,0 +1,96 @@ |
|||||
|
#if 0 |
||||
|
#include <SPI.h> |
||||
|
#include <PN532_SPI.h> |
||||
|
#include <PN532.h> |
||||
|
#include <NfcAdapter.h> |
||||
|
|
||||
|
PN532_SPI pn532spi(SPI, 10); |
||||
|
NfcAdapter nfc = NfcAdapter(pn532spi); |
||||
|
#else |
||||
|
|
||||
|
#include <Wire.h> |
||||
|
#include <PN532_I2C.h> |
||||
|
#include <PN532.h> |
||||
|
#include <NfcAdapter.h> |
||||
|
|
||||
|
PN532_I2C pn532_i2c(Wire); |
||||
|
NfcAdapter nfc = NfcAdapter(pn532_i2c); |
||||
|
#endif |
||||
|
|
||||
|
void setup() { |
||||
|
Serial.begin(115200); |
||||
|
Serial.println("NDEF Writer"); |
||||
|
nfc.begin(); |
||||
|
} |
||||
|
bool success2 = false; |
||||
|
int grabador_machine = 0; |
||||
|
String Name; |
||||
|
const int payloadLength = 50; |
||||
|
int char_count = 0; |
||||
|
byte payload[payloadLength]; |
||||
|
|
||||
|
void loop() { |
||||
|
if (Serial.available() > 0) { |
||||
|
int inByte = Serial.read(); |
||||
|
if (inByte == '#') { |
||||
|
|
||||
|
Serial.print("Name: "); |
||||
|
Serial.println(Name); |
||||
|
|
||||
|
} else { |
||||
|
Name += (char)payload[char_count]; |
||||
|
} |
||||
|
char_count++; |
||||
|
grabador_machine = !grabador_machine; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
switch (grabador_machine) { |
||||
|
case 0 : |
||||
|
Serial.println("\nPlace a formatted Mifare Classic NFC tag on the reader."); |
||||
|
if (nfc.tagPresent()) { |
||||
|
|
||||
|
success2 = nfc.format(); |
||||
|
if (success2) { |
||||
|
Serial.println("\nSuccess, tag formatted as NDEF."); |
||||
|
grabador_machine = 1; |
||||
|
} else { |
||||
|
Serial.println("\nFormat failed."); |
||||
|
} |
||||
|
} |
||||
|
delay(1000); |
||||
|
|
||||
|
break; |
||||
|
case 1 : |
||||
|
{ if (nfc.tagPresent()) { |
||||
|
NdefMessage message = NdefMessage(); |
||||
|
message.addTextRecord("Pedro Salzman", "ñ"); |
||||
|
boolean success = nfc.write(message); |
||||
|
if (success) { |
||||
|
Serial.println("Success. Try reading this tag with your phone."); |
||||
|
grabador_machine = 0; |
||||
|
} else { |
||||
|
Serial.println("Write failed"); |
||||
|
} |
||||
|
} |
||||
|
delay(1000); |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
case 2 : |
||||
|
|
||||
|
for (int c = 3; c < payloadLength; c++) { |
||||
|
Name += (char)payload[c]; |
||||
|
|
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
default : |
||||
|
{ |
||||
|
Serial.println("End"); |
||||
|
delay(11100); |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue