Need help with programming two sensors at the same time. Trying to put them in the same program. this is what ive got so far:
For the Line following:
#include “Main.h”
void main ( void )
{
SetMotor ( 1 , 50 ) ;
SteMotor ( 1 , 205 ) ;
while ( Lost<1000 )
{
Follow_Line ( ) ;
}
velcontrol ( 0 ) ;
}
For the Ultrasonic:
1.#include “Main.h”
2.
3.void ultrasonic ( void )
4.{
5. unsigned char distance = 0;
6.
7. StartUlrtrasonic ( 1 , 11 ) ;
8. distance = GetUltrasonic ( 1 , 11 ) ;
9. while ( distance > 8 )
10. {
11. SetMotor ( 3 , 0 ) ;
12. SteMotor ( 2 , 225 ) ;
13. if ( distance <= 8 )
14. {
15. SetMotor ( 3 , 127 ) ;
16. SteMotor ( 2 , 127 ) ;
17. Wait ( 1000 ) ;
18. SetMotor ( 2 , 0 ) ;
19. SteMotor ( 3 , 225 ) ;
20. Wait ( 1450 ) ;
21. distance = GetUltrasonic ( 1 , 11 ) ;
22. }
23. }
24.}
I have done the Line-Following and Ultrasonic tutorials and have gotten the two sensors to work individually, but now I am trying to put the two of them in the same program. This iswhat I have so far:
[ATTACH]3382[/ATTACH]
[ATTACH]3385[/ATTACH]
[ATTACH]3388[/ATTACH]
#include “Main.h”
void main ( void )
{
StartUlrtrasonic ( 1 , 11 ) ;
SetMotor ( 1 , 50 ) ;
SteMotor ( 1 , 205 ) ;
while ( Lost<1000 )
{
Follow_Line ( ) ;
distance = GetUltrasonic ( 1 , 11 ) ;
if ( distance < 8 ) {
break; //break while loop
}
}
velcontrol ( 0 ) ;
}
kingofl337:
#include “Main.h”
void main ( void )
{
StartUlrtrasonic ( 1 , 11 ) ;
SetMotor ( 1 , 50 ) ;
SteMotor ( 1 , 205 ) ;
while ( Lost<1000 )
{
Follow_Line ( ) ;
distance = GetUltrasonic ( 1 , 11 ) ;
if ( distance < 8 ) {
break; //break while loop
}
}
velcontrol ( 0 ) ;
}
Got this program to work. And now I have my robot following the line and stoping in front of an object. After it does this, is there any way to continue following the line if the object is removed from infront of the robot?
#include “Main.h”
void main ( void )
{
StartUlrtrasonic ( 1 , 11 ) ;
SetMotor ( 1 , 50 ) ;
SteMotor ( 1 , 205 ) ;
while ( Lost<1000 )
{
distance = GetUltrasonic ( 1 , 11 ) ;
if ( distance < 8 ) {
velcontrol ( 0 ) ;
} else {
Follow_Line ( ) ;
}
}
}