Browse Source

agregado menu

master
Hernan 5 years ago
parent
commit
a5e19a9cdb
  1. 129
      Grabador_tarjetas.ino

129
Grabador_tarjetas.ino

@ -17,67 +17,146 @@ PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c); NfcAdapter nfc = NfcAdapter(pn532_i2c);
#endif #endif
int grabador_machine = 0;
void setup() { void setup() {
Serial.begin(115200); Serial.begin(9600);
Serial.println("NDEF Writer"); Serial.println("NDEF Writer");
nfc.begin(); nfc.begin();
grabador_machine = 4;
} }
bool record_name = false;
bool valid_name = false;
bool success2 = false; bool success2 = false;
int grabador_machine = 0;
String Name; String Name;
const int payloadLength = 50; const int payloadLength = 50;
int char_count = 0; int char_count = 0;
byte payload[payloadLength]; byte payload[payloadLength];
unsigned long time_rfid;
void loop() { 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) { switch (grabador_machine) {
case 0 : case 1 :
if (time_rfid < millis()) {
Serial.println("\nPlace a formatted Mifare Classic NFC tag on the reader."); Serial.println("\nPlace a formatted Mifare Classic NFC tag on the reader.");
if (nfc.tagPresent()) { if (nfc.tagPresent()) {
success2 = nfc.format(); success2 = nfc.format();
if (success2) { if (success2) {
Serial.println("\nSuccess, tag formatted as NDEF."); Serial.println("\nSuccess, tag formatted as NDEF.");
grabador_machine = 1; grabador_machine = 4;
time_rfid = millis() + 1000;
} else { } else {
Serial.println("\nFormat failed."); Serial.println("\nFormat failed.");
grabador_machine = 4;
}
} }
time_rfid = millis() + 1000;
} }
delay(1000);
break; break;
case 1 : case 2 :
{ if (nfc.tagPresent()) { {
if (time_rfid < millis()) {
Serial.println("\nPlace a formatted Mifare Classic NFC tag on the reader.");
if (nfc.tagPresent()) {
NdefMessage message = NdefMessage(); NdefMessage message = NdefMessage();
message.addTextRecord("Pedro Salzman", "ñ"); Serial.println(Name);
message.addTextRecord(Name, "ñ");
boolean success = nfc.write(message); boolean success = nfc.write(message);
if (success) { if (success) {
Serial.println("Success. Try reading this tag with your phone."); Serial.println("Success. Try reading this tag with your phone.");
grabador_machine = 0; grabador_machine = 4;
} else { } else {
Serial.println("Write failed"); Serial.println("Write failed");
grabador_machine = 4;
}
} }
time_rfid = millis() + 1000;
} }
delay(1000);
} }
break; break;
case 2 : case 3:
if (time_rfid < millis()) {
Serial.println("Ubique una tarjeta RFID para borrar");
time_rfid = millis() + 20000;
}
if (nfc.tagPresent()) {
bool success = nfc.clean();
if (success) {
Serial.println("\nSuccess, tag restored to factory state.");
grabador_machine = 4;
} else {
Serial.println("\nError, unable to clean tag.");
grabador_machine = 4;
}
}
break;
case 4:
//if(inserted_name)
Serial.println(""); Serial.println("");
Serial.println("MENU");
Serial.println("1_Format RFID");
if (valid_name) {
Serial.println("2_Write RFID");
}
Serial.println("3_Clean RFID");
Serial.println("5_Insert Name");
Serial.print("Nombre:");
Serial.println(Name);
grabador_machine = 6;
break;
case 5:
Serial.println("Inserte el nombre y # al final");
grabador_machine = 6;
Name.clear();
record_name = true;
break;
case 6:
if (Serial.available() > 0) {
char inByte = Serial.read();
if (record_name) {
if (inByte == 35) {
grabador_machine = 4;
valid_name = true;
record_name = false;
} else {
Name += inByte;
//Name += (char)payload[char_count];
}
}
if (inByte == '1') grabador_machine = 1;
if (inByte == '2') grabador_machine = 2;
if (inByte == '3') grabador_machine = 3;
if (inByte == '5') grabador_machine = 5;
if (char_count > 50) {
char_count = 0;
}
else {
char_count++;
}
//grabador_machine = !grabador_machine;
//Serial.print(inByte);
}
break;
case 88 :
for (int c = 3; c < payloadLength; c++) { for (int c = 3; c < payloadLength; c++) {
Name += (char)payload[c]; Name += (char)payload[c];
@ -88,7 +167,7 @@ void loop() {
default : default :
{ {
Serial.println("End"); Serial.println("End");
delay(11100);
} }
break; break;

Loading…
Cancel
Save