-
-
Save parzibyte/8b34871e2bfc9b9baa28aba7b8e43bf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool escribir(char cadena[LONGITUD_BYTES_ESCRITURA]) | |
{ | |
if (!lector.PICC_IsNewCardPresent()) | |
{ | |
return false; | |
} | |
if (!lector.PICC_ReadCardSerial()) | |
{ | |
Serial.println("Error leyendo serial"); | |
return false; | |
} | |
byte bloque = 1; | |
byte buferEscritura[LONGITUD_BYTES_ESCRITURA]; | |
// Copiar cadena al búfer | |
for (uint8_t i = 0; i < LONGITUD_BYTES_ESCRITURA; i++) | |
{ | |
buferEscritura[i] = cadena[i]; | |
} | |
MFRC522::StatusCode estado; | |
estado = lector.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, bloque, &clave, &(lector.uid)); | |
if (estado != MFRC522::STATUS_OK) | |
{ | |
Serial.println("Error autenticando"); | |
Serial.println(lector.GetStatusCodeName(estado)); | |
return false; | |
} | |
estado = lector.MIFARE_Write(bloque, buferEscritura, LONGITUD_BYTES_ESCRITURA); | |
if (estado != MFRC522::STATUS_OK) | |
{ | |
Serial.println("Error escribiendo bloque"); | |
Serial.println(lector.GetStatusCodeName(estado)); | |
return false; | |
} | |
// Ya pueden retirar la tarjeta | |
lector.PICC_HaltA(); | |
lector.PCD_StopCrypto1(); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment