|
Re: heres the code. y this not working
/* Add your own autonomous code here. */
Navigate();
if(rc_dig_in01 ==1 )
{
pwm13 = 137;
pwm14=100;
}
else
{
pwm13 = pwm14 = 140;
}
if(rc_dig_in02 == 1)
{
pwm13 = 100;
pwm14 = 137;
}
else
{
pwm13 = pwm14 = 140;
}
This code will ignore the rc_dig_in01 as the if(rc_dig_in02 == 1) overwrites the values. You need to create 4 states for this or at least determine what you want to happen for each of the 4 states that can happen with two digital inputs:
rc_dig_in01 == 0, rc_dig_in02 == 0
rc_dig_in01 == 0, rc_dig_in02 == 1
rc_dig_in01 == 1, rc_dig_in02 == 0
rc_dig_in01 == 1, rc_dig_in02 == 1
I assume here that these are the inputs from a light sensor that indicates which light is seeing the tape, depending on how far away each sensor is it may not be possible to get both on at the same time. Then you are down to only 3 states. For simplicity lets define
Left == (rc_dig_in01 == 1);
Right == (rc_dig_in02 ==1);
Now:
if (Left)
{
turn right
}
else if (right)
{
turn left
}
else
{
go straight
}
if both left and right can be on at the same time then check for that first
if (Left && Right)
{
}
else if (Left)
{
}
else if (Right)
{
}
else
{
}
Hope this helps,
Dave
SBotz
|