I am having trouble programing the ultrasonic sensor. I need a code that will start up two motors until it is 15 units away from an object than i would like it to back up for 2 seconds and turn slightly to the left and then repeat this whole process. i am in great need of help. thank you
Well what do you have so far?
I scrapped this together.
void main ( void )
{
StartUltrasonic ( 1 , 11 ) ;
while ( 1 == 1 )
{
SetMotor ( 1 , 255 ) ;
SetMotor ( 2 , 0 ) ;
if ( GetUltrasonic ( 1 , 11 ) =< 15 )
{
SetMotor ( 2 , 255 ) ;
SetMotor ( 1 , 0 ) ;
Wait ( 2000 ) ;
SetMotor ( 1 , 255 ) ;
SetMotor ( 2 , 255 ) ;
Wait ( 500 ) ;
}
}
}
well i current have nothing. i just need a simple code (like the one you have) so i can get a better understanding on how to program the ultrasonic sensor. i do have one question. where is the ( getultasonic coming from i am not able to insert it in the “if” statement?
I called the function directly, instead of creating a variable using the ultrasonic get command.
ultra = GetUltrasonic(1,11);
if(ultra =< 15) {
//code
}