Changing motor rotation based on analog read

i would like to ask for advice regarding this. i have a sumobot that has 5 analog sensors for sensing enemies. 2 in front, 1 on each side and 1 on the back. the default searching is rotating right.

now, if an enemy is detected for a short period on the right, the bot will turn right because of the command to turn right when something is detected on the right sensor, even if it is not detected anymore the bot will continue turning right because of the searching and eventually it will find it then attack. this is the right response needed when the enemy is detected on the right side. however, this is not the case when the enemy is on the left because of the searching which is turning right. now, how do i change its searching when it detects the enemy on the left? how do i program it to search on the left when the last it detected is on the left, then search back on the right when it detects on the right side?

i can do this with digital inputs 1's and 0's, but i cant figure it out in analog inputs

Without code?

if ((LSF != 0) && (RSF != 0) && (LSB != 0) && (RSB != 0)) //ATTACK MODE, ALL GROUND SENSOR IS INSIDE BLACK
{
if ((DVS1 >= 150) || (DVS2 >= 150)) //I SEE AHEAD
{
Forward();
}
else if (DVS3 >= 250) //I SEE BEHIND
{
Reverse();
}
else if (DVSR >= 450) //I SEE RIGHT
{
RightRotate();
}
else if (DVSL >= 450) //I SEE LEFT
{
LeftRotate();
}
else //SEARCHING RIGHT ROTATION
{
dW(8, LOW);
dW(9, HIGH);
aW(10, 85);
aW(11, 85);
dW(12, HIGH);
dW(7, LOW);
}
}

this is the first part of my program where i should modify. i dont know what to do

Sight, snippets without code tags... ::slight_smile: "How to use the forum - please read" does not apply to you?

But in word, also have a search CCW. And have a variable in which direction to search. And when you see something on the right side, also set that variable to the right. And if you see something on the left, set that variable to the left.

In a snippet back (although I will add code tags):

bool searchRight = true;


if ((LSF != 0) && (RSF != 0) && (LSB != 0) && (RSB != 0)) //ATTACK MODE, ALL GROUND SENSOR IS INSIDE BLACK
  {
    if ((DVS1 >= 150) || (DVS2 >= 150)) //I SEE AHEAD
    {
      Forward();
    }
    else if (DVS3 >= 250) //I SEE BEHIND
    {
      Reverse();
    }
    else if (DVSR >= 450) //I SEE RIGHT
    {
      RightRotate();
      searchRight = true;
    }
    else if (DVSL >= 450) //I SEE LEFT
    {
      LeftRotate();
      searchRight = false;
    }
    else //SEARCHING RIGHT ROTATION
    {
      if(searchRight)
      {
        dW(8, LOW);
        dW(9, HIGH);
        aW(10, 85);
        aW(11, 85);
        dW(12, HIGH);
        dW(7, LOW);
      }
      else
      {
        //whatever you need to do to search left
        //and I have no clue because stupid non-explaining functions names like dw is just lazy and asking for errors
      }
    }
  }

Please read the how to use this forum post at the top of the board and use code tags when posting code.

Looks like you just need a variable to track whether you should be searching right or left. How about a Boolean called searchRight and set it true when you want to go right and false for left. You can modify it in the if statement that initially turns the bot and check it in that else to see which way to go before you start turning.

im sorry about the code i posted, im using phone on posting, i did not see where to put the code.

thank you so much, i will try that right now.

i have tried the bool function. i get the function but it still doesnt give me the response i needed. once i removed the object on the left, it goes back to searching on right when it is supposed to be searching on left now because the bool is now false.

DMS17:
i have tried the bool function. i get the function but it still doesnt give me the response i needed. once i removed the object on the left, it goes back to searching on right when it is supposed to be searching on left now because the bool is now false.

Ok well you’re the only one who can see what you did there so I’ll leave it to you to figure out what you did wrong.

Does the idea that I can’t debug what I can’t see really go that far over your head?