How can I make my robot to stop?

hey
how can I make my code repeat it self only once? I wrote this code:

int main(void)
{
//set both motors to 100 speed with pwm function
pwm_a(100);
pwm_b(100);
//delay for 2 seconds
delay_sec(2);
return 0;
}

the robot dose not stop after 2 seconds, I think he dose every thing all over again and again. I want it to stop after 2 seconds.
how do I do that?
thanks
Arbel

I’m not sure exactly which libraries you’re using, but I can guess at two things you should try.

First, the PWM function looks like it just sets a PWM duty cycle which remains until you change it, so you’ll need to set a new speed (i.e. stopped) after your delay.

Second, in most circumstances an AVR microcontroller will repeat it’s code if it reaches the end of the program memory, so if you want the robot to stay stopped, you might need to throw in an infinite loop at the end of your program, which would look something like this:

int main(void)
{
	//set both motors to 100 speed with pwm function
	pwm_a(100);
	pwm_b(100);

	//delay for 2 seconds
	delay_sec(2);

	//set both motors to stop
	pwm_a(0);
	pwm_b(0);
	
	//sit in infinite loop
	while(1);
	
	return 0;
}

I’m assuming that 0 is the stop input for your PWM function, as opposed to, say, 127.

-Adam

sounds good, I’ll give it a shot. but is there no way to either shut down the robot or to end the program without the robot repeating it?
thanks for ALL your help!!!
Arbel

The program will stop at the while(1); line, I don’t know of any other simple way to keep an AVR program from repeating.

-Adam