In C ++, which of the following solutions is more reliable and reliable for counting from 0 to 99 and storing each iteration in variables for dozens and some places? And how can any method be improved to make it as fast as possible and not resource intensive?
typedef int (*IntFunction) (int* _SegmentList);
int display1SegmentPinNums[] = {...pin numbers...};
int display2SegmentPinNums[] = {...other pin numbers...};
IntFunction displayFunctions[10] = {display_0, display_1, display_2, display_3, display_4, display_5, display_6, display_7, display_8, display_9};
for (int tens = 0; tens < 10; tens++)
{
for (int ones = 0; ones < 10; ones++)
{
displayFunctions[tens](display1SegmentPinNums);
displayFunctions[ones](display2SegmentPinNums);
}
}
for (int i = 0; i < 100; i++)
{
ones = (i % 10);
tens = ((i - ones) / 10);
displayFunctions[tens](display1SegmentPinNums);
displayFunctions[ones](display2SegmentPinNums);
}
Edit: I have included a slightly simplified version of my complete code. Hope this helps a better answer. This is for the Arduino BTW project, with 7-segment displays and an attempt to make a stopwatch.
source
share