#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);
String tagId = "None";
byte nuidPICC[4];
int button1State = 0;
int button2State = 0;
int button3State = 0;
void setup(void) 
{
 Serial.begin(115200);
 Serial.println("System initialized");
 nfc.begin();
 pinMode(2, INPUT_PULLUP);
 pinMode(3, INPUT_PULLUP);
 pinMode(4, INPUT_PULLUP);
}
 
void loop() 
{

  // read the state of the pushbutton
  button1State = digitalRead(2);
  button2State = digitalRead(3);
  button3State = digitalRead(4);
 // check if pushbutton is pressed. if it is, the
  // button state is HIGH
  if (button1State == LOW) {
    Serial.println("Submit");
  } 

  if (button2State == LOW) {
    Serial.println("Clear");
  } 

  if (button3State == LOW) {
    Serial.println("Audio");
  } 

  delay(10); // Delay a little bit to improve simulation performance
  readNFC();
}
 
void readNFC() 
{
 if (nfc.tagPresent())
 {
   NfcTag tag = nfc.read();
  //  tag.print();
   if(tag.hasNdefMessage()){
    NdefMessage msg = tag.getNdefMessage();
    NdefRecord record = msg.getRecord(0);
    // Get the payload size
    byte length = record.getPayloadLength();
    // Create byte array big enough for payload
    byte payload[length];
    // Get payload to byte array
    record.getPayload(payload);
    // Convert byte Array to string

    String string = String((char *)payload);
    int strLen = string.length() + 1;
    char data_array[strLen];
    string.toCharArray(data_array, strLen);
    Serial.write(data_array,strLen);
    String c= string.substring(3,strLen);
    Serial.println(c);
   }
 }
 delay(1000);
}