For doing that, you have to remember in which order you are running (reverse or not). So you will have a variable indicating if the order is reverse or not, and change it when you reach the extremities of your counter (0 and 3)
And you can optimize the code with using 1 and -1 for the variable which remembers order and adding it to a.
Your code will seem like this in your main :
int reverse = 1,
char a = 0;
while(1)
{
led_display(a);
delay_sec(1);
if(a==3)
{
reverse=-1;
}
if(a==0)
{
reverse=1;
}
a+=reverse;
}
Regards.
2
solved I want to blink the LED’s in reverse order [closed]