Hi all, I need some help to refine the flowchart that I have generated for the code below:
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9
#define SS_PIN 10
byte readCard[4];
byte a = 0;
LiquidCrystal_I2C lcd(0x27, 16, 2);
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
while (!Serial);
SPI.begin();
mfrc522.PCD_Init();
delay(4);
mfrc522.PCD_DumpVersionToSerial();
lcd.setCursor(2, 0);
lcd.print("Put your card");
}
void loop() {
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return 0;
}
if ( ! mfrc522.PICC_ReadCardSerial()) {
return 0;
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Scanned UID");
a = 0;
Serial.println(F("Scanned PICC's UID:"));
for ( uint8_t i = 0; i < 4; i++) { //
readCard[i] = mfrc522.uid.uidByte[i];
Serial.print(readCard[i], HEX);
Serial.print(" ");
lcd.setCursor(a, 1);
lcd.print(readCard[i], HEX);
lcd.print(" ");
delay(500);
a += 3;
}
Serial.println("");
mfrc522.PICC_HaltA();
return 1;
}
The flowchart I created:
Start
Initialize serial, LCD, and MFRC522
Print "Put your card" on LCD
Loop
Check if a new card is present
If yes, read the card's UID
Clear LCD and print "Scanned UID"
Print the UID on serial and LCD
Halt the MFRC522
Return 1
End
It shows the steps the program takes to read the UID of a card and display it on the LCD.
The first step is to initialize the serial, LCD, and MFRC522. This is done by calling the Serial.begin()
, lcd.init()
, and mfrc522.PCD_Init()
functions.
The next step is to print "Put your card" on the LCD. This is done by calling the lcd.setCursor()
and lcd.print()
functions.
The program then enters a loop. In the loop, the program checks if a new card is present. If yes, the program reads the card's UID. The UID is a unique identifier that is assigned to each card.
The program then clears the LCD and prints "Scanned UID". The UID is then printed on the serial and LCD.
The program then halts the MFRC522 and returns 1.