How to make flow chart for program

Thread Starter

Parth786

Joined Jun 19, 2017
642
I have tried many time to make flow chart for keypad program but I couldn't completed successfully. so first I have decided I will learn to make flow chart. I want to learn skill so that I can make flow chart for program before going to write c programming I have start with very basics LED and Switch. I have made three flow charts. The description are given in the PDF file.
object: If switch pressed turn ON LED ( see image 1)
object: if switch pressed turn ON LED else Turn OFF LED (see image 2)
object : if both switch 1 and switch 2 are high Turn On LED else turn OFF LED
but when I am trying to add something like as LCD. keypad, RTC. I am struggling I don't understand how to make flow chart for that purpose. so I am looking on advice how do we make flow chart ? I made flow chart for LED and switch. so how to add complexity of flow chart. How to start with easy one and than increase complexity of flow chart. please give me some advice
 

Attachments

JohnInTX

Joined Jun 26, 2012
4,601
Your problem, I think, is that you have an incomplete idea of how to accomplish your task. You have documented your incomplete solutions on the flowcharts and they are telling you that your process is incomplete. So the next step is to identify where your process if faulty and fix the process.

#1. Put your finger on START then move down to Check Switch. You proceed if the switch is TRUE but you don't show what happens if it's FALSE. Your LED box just says LED. LED what? Turn it ON? OFF? Order 100 from Mouser? What? In either case, where does the program go after that? There is no loop - does it stop, restart or what? I don't know because neither the flowchart or pseudocode says. What happens if the switch starts FALSE then goes TRUE? There is nothing to say what happens. As for the loop, you need one to keep the program running.

#2. Better but most of the same problems. No loop for one.

#3. The lack of detail in the first two is killing you here. "Check switch 1 and switch 2" Really? How?? No loop again so is it a one shot deal? No LED detail means that the flowchart is not descriptive enough.

These problems are the reason that this one stalled:
upload_2017-7-30_14-22-48.png
Trace your finger from the start again. If S1 is pressed you display '1' then what? The code stops right there according to your flowchart. What happens if the switch is not pressed? Do you really mean to look for the '+' key or should you wait (loop) until you have the first argument? As written, if no keys are pressed when the code starts, it goes straight to the bottom and maybe explodes I guess - that's not called out either.

When you finger-trace this kind of thing stop and ask yourself at each step 'What does it do if the switch is closed?' 'What does it do if the switch is open?' 'What happens if the wrong switch is pressed?'

I updated the flow chart for your two-switch LED control with these things in mind. Look at it and compare to what you had. Trace it with your finger. If it doesn't do what you want, update it. Maybe you want the LED to turn off when either switch is opened.. Update the flowchart. Finger-trace that. If you are happy, code it making sure that your code accurately reflects the flowchart. Finger-trace the code too. Finally, try it. It should do what you have coded it to do but if it DOESN'T, you have something to refer to. Maybe your logic is perfect but you haven't debounced your buttons. So make the button input a subroutine that debounces the button and returns a stable value. Fix the implementation.. The logic stays the same.

I also started to detail your 'calculator' but SURPRISE! it's not as straightforward as your flowchart indicated. It is considerably more complex in fact. That's what that flowchart was telling you. It didn't work on paper so it wasn't going to work at all. Good thing it's just on scratch paper at this point.. I may post something on it later..
 

Attachments

Last edited:

JohnInTX

Joined Jun 26, 2012
4,601
Continuing with #2 i.e. how to do a flow chart.

As noted, even simple LED stuff needs careful thought and your flowchart must actually FLOW, showing where the program goes for all possible scenarios. For a further example, I fleshed out a flowchart for a simple infix (operator between the arguments) calculator. There are 2 pages, the overall operation sequence and the input subroutine.

This is NOT intended to show a practical calculator as much as it is to get you to finger-trace a design and see where the problems are. I went through several iterations before arriving at this design and it still has some potential problems - can you find them? I'm not sure if it is even an optimal way to do infix calculations but it is where I will stop. You should read the descriptions then finger trace the flow to see how it works (or doesn't). Some things you left out in yours are addressed - notably detecting pressing and releasing the keys in a non-fixed order. It also shows looping to wait for keys, wait until fingers are off the keypad before looking for the next key.

Not shown is where the keys come from and how they are sensed. Keypad?, Individual switches? It doesn't matter at this point. The goal is to get you to be able to plan out a program before implementing anything. Each box saying something simple like Display RESULT will in turn be a collection of statements - how do you convert from the native number representation to ASCII text for the LCD display and not least, what is the native number representation you will use? Integer, Float? I don't know and this basic design leaves that undetermined since it's not important to the overall flow. It gets important when you start to drill down into those boxes and they will likely have flowcharts of their own. This process is known as 'Top-Down Design' i.e. you design and document from the big picture (top) down to the details (down).

As you can see, things get complex and you need a tool to help you organize your thoughts and design and to guide you in coding each step. And as we keep saying, if it's incomplete on paper you can't code it and if the flow doesn't work on paper, your code won't work.

Again, a calculator is a big step at this point and I don't propose to design one for you or recommend you do it either but this is how you make one big thing into lots of manageable little things.

EDIT: a final note, the PDFs are a just a way to get a nice looking document here. The real work was done in over several pages with lots of scribbled pencil then refined from there. Don't try to design on the computer - just scribble it out. Make it pretty when it works.

Good luck.
 

Attachments

Last edited:

Thread Starter

Parth786

Joined Jun 19, 2017
642
Your problem, I think, is that you have an incomplete idea of how to accomplish your task. You have documented your incomplete solutions on the flowcharts and they are telling you that your process is incomplete. So the next step is to identify where your process if faulty and fix the process.

That's what that flowchart was telling you. It didn't work on paper so it wasn't going to work at all. Good thing it's just on scratch paper at this point.. I may post something on it later..
I am really sorry for late reply. I had some personal issues so I couldn't reply back. Yes I understand the importance of flow chart in programming. I am really interested on making automatic projects so I know I need to write c programming. and I wrote some programs without flow chart but as you suggested first draw flow chart than write program.so that the reason I want learn to make flow chart before coding. I attached document to show you that I started to learn with very basics so I just used only LED and switch and my main purpose is that , I want to learn skill " drawing flow chart for any program". I know there are many source available but I think its better if you suggest me some simple exercise ( Like as I started with LED ).
 

Thread Starter

Parth786

Joined Jun 19, 2017
642
??
Exercises are in posts #2 and #4.
I have made some flow charts. look attached file but still have some confuse
where to draw box for Loop ( while loop)?
In third diagram, there is one box "LED ON" his connection doesn't go anywhere. I think it should be connect somewhere. once i feel that I understand flow chart for LED than I will go with LCD. I will make some flow chart for LCD and after that I will try to make with LCD and switches
 

Attachments

JohnInTX

Joined Jun 26, 2012
4,601
I have made some flow charts. look attached file but still have some confuse
where to draw box for Loop ( while loop)?
In third diagram, there is one box "LED ON" his connection doesn't go anywhere. I think it should be connect somewhere. once i feel that I understand flow chart for LED than I will go with LCD. I will make some flow chart for LCD and after that I will try to make with LCD and switches
So what do you want it to do after you turn the LED on? Stop there forever or go back and check the switches again like you did in LED off?

Did you look at my PDF in post #2? That shows you what to do along with the code. Do you understand it?
 

Thread Starter

Parth786

Joined Jun 19, 2017
642
So what do you want it to do after you turn the LED on? Stop there forever or go back and check the switches again like you did in LED off?

Did you look at my PDF in post #2? That shows you what to do along with the code. Do you understand it?
I understand flow chart for LED but still I am struggling for complex program . can you help me to draw flow chart for addition only. I am not getting idea with flow chart that you posted for calculator. I really couldn't decide where I am mistaking.
 

JohnInTX

Joined Jun 26, 2012
4,601
I did a new flow chart showing your basic 1+1=2 switch-based calculator. You should be able to follow it. It shows things you didn't think of such as waiting until fingers are off the switches before proceeding to look at them again. It is also organized so that you can see how many sequences could be combined into subroutines or functions to make it simpler to code. The RED labels are so you can ask questions and refer to a specific section.

I identified the main loop. That all goes inside the main while(1). The sub-loops are how you wait for events like a switch push or all switches clear. They will also be while or do loops with a condition that breaks out of the loop for example when a switch is pushed.

I don't think I can make it any simpler.

Good luck.
 

Attachments

Thread Starter

Parth786

Joined Jun 19, 2017
642
I did a new flow chart showing your basic 1+1=2 switch-based calculator. You should be able to follow it. It shows things you didn't think of such as waiting until fingers are off the switches before proceeding to look at them again. It is also organized so that you can see how many sequences could be combined into subroutines or functions to make it simpler to code. The RED labels are so you can ask questions and refer to a specific section.

I identified the main loop. That all goes inside the main while(1). The sub-loops are how you wait for events like a switch push or all switches clear. They will also be while or do loops with a condition that breaks out of the loop for example when a switch is pushed.

I don't think I can make it any simpler.

Good luck.
Thanks for making simple. so flow chart is ready Now can I try to write program according to flow chart. I just want to confirm that program work according to flow chart. just want to see what will be result.Can I start to write program?
 

JohnInTX

Joined Jun 26, 2012
4,601
Well, you should convince yourself that the flow chart does what you want it to do by going along the various paths.
After that, have at it.
 

WBahn

Joined Mar 31, 2012
26,398
Thanks for making simple. so flow chart is ready Now can I try to write program according to flow chart. I just want to confirm that program work according to flow chart. just want to see what will be result.Can I start to write program?
You might benefit from working with a programming environment called Raptor. It's an educational language, but your flowchart and your program are one and the same.

https://en.wikipedia.org/wiki/Raptor_(programming_language)
 
Top