dann hab ich noch eine Frage zum Thema verzögerung sprich (delay)

ich habe hier einen code den ich nicht verstehe

void delay(long delay){
int i, dummy;
for(i=0; i<delay; i++)
{
dummy++;
}
}

wenn ich also einen Befehl schreibe zum beispiel

while(1){

if(switch1 == 0){
driveForward();
STATSLED1_OFF;
}

else if (switch1 == 1){
driveBackward();
delay(10000)
turnRIGHTforward();
STATSLED1_OFF;
}


}
}

muss ich jetzt das so schreiben ?

turnRIGHTforward();
delay(10000)


oder einfach so lassen turnRIGHTforward();

wenn das richtig ist wiso funktioniert das dann hier nicht ?



#include <avr/io.h>
//#include <iom88.h>


#define STATSLED0_ON (PORTC |= 1<<PC0)
#define STATSLED0_OFF (PORTC &= ~(1<<PC0))
#define STATSLED1_ON (PORTC |= 1<<PC1)
#define STATSLED1_OFF (PORTC &= ~(1<<PC1))

#define GET_IRSEN_RIGHT (PIND & 1<<PD4)
#define GET_IRSEN_LEFT (PIND & 1<<PD3)

void driveForward(){

// Motor 1 Forward
PORTD |= 1<<PD6;
PORTD &= ~(1<<PD7);
// Motor 2 Forward
PORTB |= 1<<PB2;
PORTB &= ~(1<<PB1);

}

void turnLEFTforward(){

// Motor 1 stop
PORTD |= 1<<PD6;
PORTD |= 1<<PD7;
// Motor 2 Forward
PORTB |= 1<<PB2;
PORTB &= ~(1<<PB1);

}

void turnRIGHTforward(){

// Motor 1 Forward
PORTD |= 1<<PD6;
PORTD &= ~(1<<PD7);
// Motor 2 stop
PORTB |= 1<<PB2;
PORTB |= 1<<PB1;

}

void stop(){

// Motor 1 stop
PORTD |= 1<<PD6;
PORTD |= 1<<PD7;
// Motor 2 stop
PORTB |= 1<<PB2;
PORTB |= 1<<PB1;

}

void driveBackward(){

// Motor 1 backward
PORTD &= ~(1<<PD6);
PORTD |= 1<<PD7;
// Motor 2 backward
PORTB &= ~(1<<PD2);
PORTB |= 1<<PD1;
}

void turnLEFTbackward(){
// Motor 1 backward
PORTD &= ~(1<<PD6);
PORTD |= 1<<PD7;
// Motor 2 stop
PORTB |= 1<<PD2;
PORTB |= 1<<PD1;
}

void turnRIGHTbackward(){
// Motor 1 stop
PORTD |= 1<<PD6;
PORTD |= 1<<PD7;
// Motor 2 backward
PORTB &= ~(1<<PD2);
PORTB |= 1<<PD1;
}

void delay(long delay){
int i, dummy;
for(i=0; i<delay; i++)
{
dummy++;
}
}

int main(void){

DDRD = 1<<PD6 | 1<<PD7; // PD6 PD7 Output Motor1;
DDRB = 1<<PB1 | 1<<PB2; // PB1 PB2 Output Motor2;


DDRD &= ~(1<<PD3 | 1<<PD4); // PD3 PD4 Input IR Sensors;

DDRC = 1<<PC0 | 1<<PC1; // PC0 PC1 Output StatusLED0 & 1;



//PORTD &= ~(1<<PD6);
//PORTD &= ~(1<<PD7);


while(1){

if( GET_IRSEN_RIGHT ) STATSLED0_ON;
else STATSLED0_OFF;

if( GET_IRSEN_LEFT ) STATSLED1_ON;
else STATSLED1_OFF;


if(! GET_IRSEN_RIGHT && ! GET_IRSEN_LEFT){
driveForward();
STATSLED0_OFF;
STATSLED1_OFF;
}

else if(GET_IRSEN_RIGHT && GET_IRSEN_LEFT){
driveBackward();
delay(10000);
turnRIGHTbackward();
delay(10000);
STATSLED0_ON;
STATSLED1_ON;
}


//PORTC = 1<<PC5;

//PORTC = 0<<PC5;


}
}