I am currently working on a 4 digit 7 segment display that displays the seconds in real time. To make the number on the display change as time goes on I am using a for loop that increases a variable by one for every second. I want to use this variable in real time, but the scope seems to be wrong so I cannot access the variable. I have tried to intialize a variable outside of the for loop scope, but when I try to use that variable it only gives me the last number as the loop ends, not the variable as it changes in the loop. Here is my code.
int x = 0;
for(sec = 0; sec<10; sec++)
x = sec;
I want to display “x” on the display in real time as it changes due to the loop, how can I do this?
Thanks in advance.