I am using an RFID card reader and I've been messing around with the sample code. It uses a string to store the read card but I would rather use a char array.
//content holds card's UIDs
String content = "";
//Reads UID
if(mfrc522.uid.size != 4){
return;
}
for (byte i = 0; i < mfrc522.uid.size; i++)
{
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
//formats content
content.toUpperCase();
content.replace(" ", "");
for (unsigned int i = 0; i < content.length(); i++) {
rcv[i] = content[i];
}
Serial.println(rcv);
I would like to change 'content' to a char array to put less strain on my Arduino nano. Thanks!
2 indicates that the conversion will be at least two characters (sufficient for a byte), the 0 indicates to pd with a leading zero and the X does a uppercase hexadecimal text representation (x would do a lowercase).
here's a function that reads a complete line, terminated by a '\n', into a limited size char array
int
readString (
char *s,
int maxChar )
{
int n = 0;
Serial.print ("> ");
do {
if (Serial.available()) {
int c = Serial.read ();
if ('\n' == c)
break;
s [n++] = c;
if (maxChar == n)
break;
}
} while (true);
return n;
}