Need Help w/ code flow chart (Using Visio)

Looking for some insight on how to represent these for statements on a flow chart. the code is mostly our teachers. its a 4 digit, 7 segment display. she had us modify it to count 0000 to 9999, than back down from 9999 to 0000. wasnt very hard to do this. our project was mainly revolving around wiring it up. as far as explaining its process in a flowchart, im kind of at a loss. this is a micro-credential class that im taking to help my odds of getting into a electrical apprenticeship. thank you


int segments[8] = { 12, 11, 10, 9, 8, 7, 6, 5 };  // dp, a, b, c, d, e, f, g
int DigitsEnable[4] = { 4, 3, 2, 1 };             // digits 1, 2, 3, 4 control (left to write)

int OneCharDelay = 1;     // delay between digits
int CounterRepeats = 30;  // Set the number of times the counting should be repeated


//   Mapping to      digits and letters to dp, a,b,c,d,e,f,g of Seven-Segment LED
int seven_seg_digits[][8] = {
  { 0, 1, 1, 1, 1, 1, 1, 0 },  // = 0    // = 0
  { 0, 0, 1, 1, 0, 0, 0, 0 },  // = 1    // = 1
  { 0, 1, 1, 0, 1, 1, 0, 1 },  // = 2    // = 2
  { 0, 1, 1, 1, 1, 0, 0, 1 },  // = 3    // = 3
  { 0, 0, 1, 1, 0, 0, 1, 1 },  // = 4    // = 4
  { 0, 1, 0, 1, 1, 0, 1, 1 },  // = 5    // = 5
  { 0, 1, 0, 1, 1, 1, 1, 1 },  // = 6    // = 6
  { 0, 1, 1, 1, 0, 0, 0, 0 },  // = 7    // = 7
  { 0, 1, 1, 1, 1, 1, 1, 1 },  // = 8    // = 8
  { 0, 1, 1, 1, 1, 0, 1, 1 },  // = 9    // = 9
  { 0, 1, 1, 1, 0, 1, 1, 1 },  // = 10   // = A
  { 0, 0, 0, 1, 1, 1, 1, 1 },  // = 11   // = b
  { 0, 1, 0, 0, 1, 1, 1, 0 },  // = 12   // = C
  { 0, 1, 0, 0, 1, 1, 1, 1 },  // = 13   // = E
  { 0, 1, 0, 0, 0, 1, 1, 1 },  // = 14   // = F
  { 0, 1, 0, 0, 0, 1, 1, 1 },  // = 15   // = G
  { 0, 0, 1, 1, 0, 1, 1, 1 },  // = 16   // = H
  { 0, 0, 0, 0, 0, 1, 1, 0 },  // = 17   // = I
  { 0, 1, 1, 0, 0, 1, 1, 1 },  // = 18   // = P
  { 0, 1, 1, 1, 1, 0, 1, 1 },  // = 19   // = q
  { 0, 0, 0, 0, 0, 1, 0, 1 },  // = 20   // = r
  { 0, 1, 0, 1, 1, 0, 1, 1 },  // = 21   // = S
  { 0, 0, 0, 0, 1, 1, 1, 1 },  // = 22   // = t
  { 0, 0, 1, 1, 1, 1, 1, 0 },  // = 23   // = U
  { 0, 0, 0, 0, 1, 1, 1, 0 },  // = 24   // = L
  { 0, 0, 0, 0, 0, 0, 0, 0 },  // = 25   // = OFF
};

int seven_seg_digits_OFF[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };

int MyText1[4] = { 13, 24, 13, 12 };  // 'ELEC'
int MyText2[4] = { 25, 1, 0, 2 };     // ' 102'


void setup() {

  // initialize all LED drive signals to output
  for (int i = 0; i < 8; i++) {
    pinMode(segments[i], OUTPUT);
  }
  for (int i = 0; i < 4; i++)  // Iterate through the DigitsEnable array to configure pin modes for each digit
  {
    pinMode(DigitsEnable[i], OUTPUT);  // Set the pin mode to OUTPUT for the specified digit
  }
}

void loop() {
  DemoCounter();         // Count 0000-9999
  DemoReverseCounter();  // Count 9999-0000
}

void DisplayChar(int OneChar, int DigitToEnable)

{
  for (int segment = 0; segment < 8; segment++)  // check which segments should be turned ON (1) or off (0)
  {
    if (seven_seg_digits[OneChar][segment] == 1) {
      digitalWrite(segments[segment], HIGH);  // Turn on segment
    } else {
      digitalWrite(segments[segment], LOW);  // If not, turn the segment OFF (0)
    }
  }

  // Enable the specific digit for display
  digitalWrite(DigitToEnable, HIGH);  //Enable the digit
  delay(OneCharDelay);                // Delay for OneCharDelay milliseconds
  digitalWrite(DigitToEnable, LOW);   // Disable the digit
}

void DemoCounter()  // Function to count with multiple nested loops. 0 to 9999.
{
  for (int digitsThousands = 0; digitsThousands < 10; digitsThousands++)  // Iterate through digitsThousands from 0 to 9
  {
    for (int digitsHundreds = 0; digitsHundreds < 10; digitsHundreds++)  // Iterate through digitsHundreds from 0 to 9
    {
      for (int digitsTens = 0; digitsTens < 10; digitsTens++)  // Iterate through digitsHundreds from 0 to 9
      {
        for (int digitsOnes = 0; digitsOnes < 10; digitsOnes++)  // Iterate through digitsOnes from 0 to 9
        {
          for (int t = 0; t < CounterRepeats; t++)  // Iterate through digits from 0 to 9
          {
            // Display the individual digits on their respective segments
            DisplayChar(digitsOnes, DigitsEnable[3]);
            DisplayChar(digitsTens, DigitsEnable[2]);
            DisplayChar(digitsHundreds, DigitsEnable[1]);
            DisplayChar(digitsThousands, DigitsEnable[0]);
          }
        }
      }
    }
  }
}

void DemoReverseCounter()  // Function to count with multiple nested loops. Reversed 9999 to 0
{
  for (int digitsThousands = 9; digitsThousands > -1; digitsThousands--)  // Iterate through digitsThousands from 9 to 0
  {
    for (int digitsHundreds = 9; digitsHundreds > -1; digitsHundreds--)  // Iterate through digitsHundreds from 9 to 0
    {
      for (int digitsTens = 9; digitsTens > -1; digitsTens--)  // Iterate through digitsTens from 9 to 0
      {
        for (int digitsOnes = 9; digitsOnes > -1; digitsOnes--)  // Iterate through digitsOnes from 9 to 0
        {
          for (int t = 0; t < CounterRepeats; t++)  // Iterate through digits from 9 to 0
          {
            // Display the individual digits on their respective segments
            DisplayChar(digitsOnes, DigitsEnable[3]);
            DisplayChar(digitsTens, DigitsEnable[2]);
            DisplayChar(digitsHundreds, DigitsEnable[1]);
            DisplayChar(digitsThousands, DigitsEnable[0]);
          }
        }
      }
    }
  }
}

Welcome! Please read the forum guide lines and post your code using code tags. It makes it much easier to follow.

That's a part found in programming courses.

you are correct, that's why its part of my assignment. your comment was not very helpful though. thanks...

not exactly sure on how, sorry. this class I am taking is suppose to be a beginners class. its also the first time they taught this class. so its not going very smooth. teacher struggles to get info to students, behind on grading our work so we have nothing to critique off of..

What help do you expect from the members of the forum?

We are not here to do your homework.

1 Like

Well you could always


But it's easy enough:

First use the IDE Autoformat tool on your code.

Then copy the code in its entirety.

Finally come back here, and posting, use the <CODE/> tool in the message composition window toolbar, and do what it will tell you to, viz:

type or paste code here

So it ends up looking line code:

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

HTH and good luck with your studies. No one was born knowing any of this, and many of us are still learning something every day.

a7

thank you

What kind of comment do You search then? The idea for this forum is help members learn and grow in programming. Forum is not a quick fix shop and free give away.

heres kinda what i got going on, still working on it..

Quick hint: when several lines all go to the same block and are parallel, custom is to just make a single line and connect the stubs to that one line.

I realize that this is a coursework assignment so you have no control, but I have found flowcharts to be of minimal help on anything larger than learning exercises.

They seem to be something that the teacher assigns because it has always been done that way.

If you get a chance to comment on the new course, see if you can find a diplomatic way to suggest dropping flowcharts.

I’ll bet that your instructor really loves comments in the code too :wink:

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