I want to make a program looping over array and then looping backwards. How can I make it better with less code in C? Array has 8 elements!
while (1) {
if (i == 0) {
direction = 0; // RIGHT DIRECTION
}
if (i == 7) {
direction = 1; // LEFT DIRECTION
}
PORTD = array[i]; // NEEDED ARRAY ELEMENT
if (direction == 0) {
i++;
} else {
i--;
}
}
1or-1. Then add it toi. But you need stop condition too.arrayis for thoughint array [] = {0b00000001,0b00000010,0b00000100,0b00001000,0b00010000,0b00100000,0b01000000,0b10000000};