Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Mifare Ultracard writer
- // Written by: Samuel Duclos
- // Creative Commons License
- #include <SPI.h>
- #include <MFRC522.h>
- #define RST_PIN 9
- #define SS_PIN 10
- char i = 0, k = 0, input[] = {',',',',',',',',',',',',',',','};
- byte page = 0, buffer[4];
- MFRC522 mfrc522(SS_PIN, RST_PIN);
- void setup() {
- Serial.begin(9600);
- SPI.begin();
- mfrc522.PCD_Init();
- Serial.println("Ultracard writer by Samuel Duclos, under Creative Commons License");
- Serial.println("Writings to pages 2 and 3 are permanent!!");
- Serial.println("Enter page# [02-0F]:");
- }
- void loop() {
- while (!Serial.available());
- Serial.readBytesUntil('\n', input, 6);
- page = (byte)strtol((char *)input, NULL, 16);
- Serial.println("Enter 4 bytes separated by \"ENTER\" strokes:");
- do {
- // for(char j = 0; j < sizeof(input); j++) input[j] = 0;
- memset(input, 0, sizeof(input));
- k = Serial.available();
- while (k == Serial.available());
- Serial.readBytesUntil('\n', input, 6);
- buffer[i] = (byte)strtol((char *)input, NULL, 16);
- } while (++i < 3);
- Serial.println("You may now scan the card...");
- while (1) {
- if(!mfrc522.PICC_IsNewCardPresent()) continue;
- if (!mfrc522.PICC_ReadCardSerial()) continue;
- Serial.println(
- mfrc522.GetStatusCodeName(
- mfrc522.MIFARE_Ultralight_Write(
- page, (byte *)buffer, 4)));
- }
- }
Add Comment
Please, Sign In to add comment