I changed the code of nfc 532 but I wanted to make an alteration and I do not know how. Want to give a time out? That is, when I did not put the mobile phone at the foot of the chip during the wait this one leaves the code. That is, I am always waiting I put the mobile phone on the chip to send information, but it may happen that I do not put it, and as it is I always wait. Wanted for a timeout type 10 seconds as a stopwatch
#include "SPI.h"
#include "PN532_SPI.h"
#include "snep.h"
#include "NdefMessage.h"
PN532_SPI pn532spi(SPI, 10);
SNEP nfc(pn532spi);
uint8_t ndefBuf[128];
const int buttonPin = 6;
int buttonState = 0;
void setup()
{
Serial.begin(115200);
pinMode(7, OUTPUT);
}
int var=0;
boolean Acender=0;
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == 1) {
digitalWrite(7,HIGH); //Desliga rele 2
Serial.println("Send a message to Android");
NdefMessage message = NdefMessage();
message.addTextRecord("Alertas acidente: DADOS");
int messageSize = message.getEncodedSize();
if (messageSize > sizeof(ndefBuf)) {
Serial.println("ndefBuf is too small");
while (1) {
}
}
message.encode(ndefBuf);
if (0 >= nfc.write(ndefBuf, messageSize)) {
Serial.println("Failed");
} else {
Serial.println("Success");
}
// Serial.println("Failed");
}
else{
digitalWrite(7,LOW); //Desliga rele 2
}
}