Help to refine the flowchart below

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.

chatGPT ?

If you use the auto format tool in the IDE on your code, its structure should describe your code better than a flowchart.

Not really a flow chart, given that is diagrammatic, you are trying to write pseudo code to describe the steps your programming should follow.

I was taught to use Pascal for the pseudo code, but any textual description to help you write the program is a boon.

It helps you sort out in your mind the steps you have to take to complete the task in hand.
Diagrammatic flow chart first, then pseudo code which are both roadmaps to programme writing

In your case you started with Initialise serial etc, but the step before that is initialise all known variables to be used, which you would know from the flow chart.

As SemperIdem says, you need to format your program which makes it easier for you to spot mistakes.

Please explain in detail what the help you need

not clear if your notes are intended to give a general idea or a complete, correct and unambiguos description for someone to implement the notes as code that will work correctly

are the notes intended to describe "what" needs to be done or "how" exactly to do it. would it be sufficient to say, "if a card is available, read and display its UID on the LCD and serial I/F".

does your reader understand

  • that the serial i/f bit rate needs to be set
  • hot to initialize the LCD and mfrc522
  • what should the code do a card is not present
  • how to clear the LCD
  • at what cursor position to display "Scanned UID"
  • that the UID is read one byte at a time
  • how many bytes there are
  • at what cursor position to display the UID bytes
  • what does the code do to "Return 1"
  • how exactly does the code "End"
while ( ! mfrc522.PICC_IsNewCardPresent() ||  ! mfrc522.PICC_ReadCardSerial()) {;}

How?
Flow Chart is a visual representation; whereas, codes are textual representation?

You put text in the boxes, don't you?

It used to be that algorithms were formally (in computing papers) described in Algol-60

Typical Flowchart.

Tom.. :smiley: :+1: :coffee: :australia:

2 Likes

i can't think of a time i used a flow chart during my career

however, i did use

  • structure charts
  • data flow diagrams
  • state diagrams
  • timing diagrams
  • message charts
1 Like

Hi,
I've used flowcharts in about 50% of my projects, but usually go to pseudo code.
That's because pseudo code is like I am talking to myself, I get the better results that way.

Tom.. :smiley: :+1: :coffee: :australia:

1 Like

This is a practical Flow Chart that I chalked out to develop the Program for receiving an Intel-Hex formatted file being transmitted from IBMPC to 89S52 Microcontroller Trainer.

1 Like

As an image, how much storage does that take up?
As implemented code, how much storage does that take up?

What does the image show you that the code doesn't?

(I get that you might want to flowchart an industrial process for troubleshooting purposes when a valve sticks, or someone pours sugar in the diesel tank, but once you've thoroughly tested the code for an immutable protocol, what really is the point?

"Show me your flowchart and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won't usually need your flowchart; it'll be obvious." -- Fred Brooks, The Mythical Man Month (1975)

1 Like

61.5 KByte
A component of 4 Kbyte Monitor Program and is about less than 1 Kbyte.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.