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]);
}
}
}
}
}
}