Update examples, use F() macro

Saves a lot of memory, examples now run at a arduino uno
This commit is contained in:
rotzbua
2015-02-23 16:07:08 +01:00
parent 6f4b6c4007
commit 0ccfb06aa5
7 changed files with 104 additions and 103 deletions

View File

@@ -30,7 +30,7 @@ void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println("Write personal data on a MIFARE PICC ");
Serial.println(F("Write personal data on a MIFARE PICC "));
}
void loop() {
@@ -47,12 +47,12 @@ void loop() {
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) return;
Serial.print("Card UID:"); //Dump UID
Serial.print(F("Card UID:")); //Dump UID
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.print(" PICC type: "); // Dump PICC type
Serial.print(F(" PICC type: ")); // Dump PICC type
byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));
@@ -62,33 +62,34 @@ void loop() {
Serial.setTimeout(20000L) ; // wait until 20 seconds for input from serial
// Ask personal data: Family name
Serial.println("Type Family name, ending with #");
Serial.println(F("Type Family name, ending with #"));
len=Serial.readBytesUntil('#', (char *) buffer, 30) ; // read family name from serial
for (byte i = len; i < 30; i++) buffer[i] = '\s'; // pad with spaces
block = 1;
//Serial.println("Authenticating using key A...");
//Serial.println(F("Authenticating using key A..."));
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print("PCD_Authenticate() failed: ");
Serial.print(F("PCD_Authenticate() failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else Serial.println(F("PCD_Authenticate() success: "));
// Write block
status = mfrc522.MIFARE_Write(block, buffer, 16);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Write() failed: ");
Serial.print(F("MIFARE_Write() failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else Serial.println("MIFARE_Write() success: ");
else Serial.println(F("MIFARE_Write() success: "));
block = 2;
//Serial.println("Authenticating using key A...");
//Serial.println(F("Authenticating using key A..."));
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print("PCD_Authenticate() failed: ");
Serial.print(F("PCD_Authenticate() failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
@@ -96,22 +97,22 @@ void loop() {
// Write block
status = mfrc522.MIFARE_Write(block, &buffer[16], 16);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Write() failed: ");
Serial.print(F("MIFARE_Write() failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else Serial.println("MIFARE_Write() success: ");
else Serial.println(F("MIFARE_Write() success: "));
// Ask personal data: First name
Serial.println("Type First name, ending with #");
Serial.println(F("Type First name, ending with #"));
len=Serial.readBytesUntil('#', (char *) buffer, 20) ; // read first name from serial
for (byte i = len; i < 20; i++) buffer[i] = '\s'; // pad with spaces
block = 4;
//Serial.println("Authenticating using key A...");
//Serial.println(F("Authenticating using key A..."));
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print("PCD_Authenticate() failed: ");
Serial.print(F("PCD_Authenticate() failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
@@ -119,17 +120,17 @@ void loop() {
// Write block
status = mfrc522.MIFARE_Write(block, buffer, 16);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Write() failed: ");
Serial.print(F("MIFARE_Write() failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else Serial.println("MIFARE_Write() success: ");
else Serial.println(F("MIFARE_Write() success: "));
block = 5;
//Serial.println("Authenticating using key A...");
//Serial.println(F("Authenticating using key A..."));
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print("PCD_Authenticate() failed: ");
Serial.print(F("PCD_Authenticate() failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
@@ -137,11 +138,11 @@ void loop() {
// Write block
status = mfrc522.MIFARE_Write(block, &buffer[16], 16);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Write() failed: ");
Serial.print(F("MIFARE_Write() failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else Serial.println("MIFARE_Write() success: ");
else Serial.println(F("MIFARE_Write() success: "));
Serial.println(" ");