Hello guys so i've already posted here once about this when i couldn't get the result for my code. Now i'm obtaining the result properly but i need to optimize it in the serial monitor. Can anyone help me with this?
This is my code:
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);
int a,c1=0;
void setup()
{
Serial.begin(9600);
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
mfrc522.PCD_DumpVersionToSerial();
Serial.println("Approximate your card to the reader...");
Serial.println();
Serial.println("ENTER THE STUDENT IDENTIFICATION CODE");
}
void loop()
{
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
if(mfrc522.uid.uidByte[0]==0x0c && mfrc522.uid.uidByte[1]==0x8c && mfrc522.uid.uidByte[2]==0x91 && mfrc522.uid.uidByte[3]==0x79)
{
Serial.println("WELCOME /n 1.ISSUE /n 2.RENEWAL /n 3.RETURN");
delay(3000);
if(Serial.available()>0)
{
//Serial.println("Hello");
a=Serial.read();
}
switch(a)
{
case 49:
Serial.println("Scan the book for issue");
delay(3000);
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
if(mfrc522.uid.uidByte[0]==0x51 && mfrc522.uid.uidByte[1]==0xc5 && mfrc522.uid.uidByte[2]==0x11 && mfrc522.uid.uidByte[3]==0x2e && c1==0)
{
Serial.println("Book 1 has been issued");
c1=1;
}
else
{
Serial.println("Book 1 has already been issued. Please renew it");
}
break;
case 50:
Serial.println("Scan the book for renew");
delay(3000);
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
if(mfrc522.uid.uidByte[0]==0x51 && mfrc522.uid.uidByte[1]==0xc5 && mfrc522.uid.uidByte[2]==0x11 && mfrc522.uid.uidByte[3]==0x2E && c1==1)
{
Serial.println("Book 1 has been renewed");
}
else
{
Serial.println("Book 1 has'nt been issued yet. Please issue it to renew");
}
break;
case 51:
Serial.println("Scan the book to return");
delay(3000);
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
if(mfrc522.uid.uidByte[0]==0x51 && mfrc522.uid.uidByte[1]==0xc5 && mfrc522.uid.uidByte[2]==0x11 && mfrc522.uid.uidByte[3]==0x2e && c1==1)
{
Serial.println("Book 1 has been returned");
c1=0;
}
else
{
Serial.println("Book 1 hasn't been issued yet. please issue the book to return it.");
}
break;
default:
Serial.print("Invalid option");
break;
}
}
}
So the output of the code on the serial monitor is something like shown in the picture.
i.e whenever i scan a card i get it's sector block too. Is there anyway to remove just the sector block from being printed in the serial monitor? Other than that the code works as intended. Thank you.