advies for my flowchart

i am trying to make my program to understand so i made a flowchart , my question is did i made it good . any advies would be nice or correction .

int
counter = 0;



int
counterDir = 0 ;



int
buttonState = 0;



int
lastButtonState = 0;



void
setup() {



  pinMode(8, INPUT_PULLUP);



  pinMode(9, INPUT_PULLUP);



  pinMode(4, OUTPUT);



  pinMode(5, OUTPUT);



  pinMode(6, OUTPUT);



  Serial.begin(9600);



}



void
loop() {



  buttonState = digitalRead(8);



  if (buttonState != lastButtonState)//
buttonstate staat van de button lastbuttonstate vorige staat



  {



    if (buttonState == LOW)



    {



      counterDir = !counterDir;



    }



    lastButtonState = buttonState;



    delay(200);



  }



  buttonState = digitalRead(9);



  if (buttonState != lastButtonState)



  {



    if (buttonState == LOW)



    {



      if (counterDir == HIGH)



      {



        counter++;



      }



      else



      {



        counter--;



      }



      if (counter < 0) counter = 2;



      if (counter > 2) counter = 0;



    }



    lastButtonState = buttonState;



    delay(200);



  }



  if (counter == 0)

Triangles are for decisions, not statements. Your flow chart is ONE-TIME only. Do you want to process only one time? IF more than once, you need a loop back to some beginning point.
Paul

Triangles are for decisions

Triangles?

PerryBebbington:
Triangles?

Yeah back-to-back!
Paul

Do you think it wise to use the same lastButtonState variable for both buttons? I don't.

Why so much white space (blank lines) in your code? It makes it more difficult to read and follow.

my bad seems my code didnt copy good to the forum . i added a new flowchart

int counter = 0;
int counterDir = 0 ;
int buttonState = 0;
int lastButtonState = 0;
void setup() {
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  Serial.begin(9600);
}
void loop() {
  buttonState = digitalRead(8);
  if (buttonState != lastButtonState)// buttonstate staat van de button lastbuttonstate vorige staat
  {
    if (buttonState == LOW)
    {
      counterDir = !counterDir;
    }
    lastButtonState = buttonState;
    delay(200);
  }
  buttonState = digitalRead(9);
  if (buttonState != lastButtonState)
  {
    if (buttonState == LOW)
    {
      if (counterDir == HIGH)
      {
        counter++;
      }
      else
      {
        counter--;
      }
      if (counter < 0) counter = 2;
      if (counter > 2) counter = 0;
    }
    lastButtonState = buttonState;
    delay(200);
  }
  if (counter == 0)

My best ‘decision’ was a Diamond :slight_smile:

The rectangles rotated 45 degrees should contain a test. Could be

if (data > limit)

.
There are always 2 exits. One Yes and one No. Each of them is followed by som code.
After the correct "delay(200)" such a test block is needed in order to decide for ++ or --.

The diagram could start with a "normal block" like "readButtons" followed by a test blocks "if (button1)", a Yes or No exit. The No will then test for "button2".

counter++/counter-- is madein a diamond somehow it made it bigger . my question is the roadmap correct like my program

Pleas post updated pictures in the last post.
That diamond is not used correctly. Read my previous reply.

The connection from the bottom up backwards is fine. You need a block updating where lastbutton state gets its value and "buttonstate" gets its new value.

Thinking the right way, the order how variables change, will be clearly visualized in the flow chart and save lots of debugging.

You need to go to the google school of flowcharting.

Srsly, thus looks like you saw a flowchart at some point in your life and now you are totally winging it. Your diagram is nearly meaningless and certainly is not useful for programming or documentation.

Find some tutorial that matches your learning style and get a grip on basic flowcharting.

a7

Who still has an IBM plastic flow charting template?
Paul

Paul_KD7HB:
Who still has an IBM plastic flow charting template?
Paul

Here


OP here is an example:

@larryd
That's the way it should look!

i am sorry if i use IBM plastic flow charting . thank you larryd for the example

I moved from an all IBM service bureau to another service bureau that was mostly Burroughs computers, but they did have an IBM 360-30. None of the programmers had a flow charting template. Hard to imagine. No one knew the templates and lots of other stuff was free from IBM if you had an IBM computer.
I ordered 6 or 7 plastic templates. A few weeks later a large package arrived from IBM. Was full of plastic templates. I had failed to notice the product number had a dozen quantity for the order. So, 6 or 7 times 12 gave everyone at least one template!
Paul

larryd:
My best ‘decision’ was a Diamond :slight_smile:

Good one....

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