Go Down

Topic: when x and d == some value....do this one time. (Read 395 times) previous topic - next topic

Warrior

When my robot is centered(variable x) to the object, and when my distance is equaled to some amount(variable d). I would like it to drop my arm() function, do it once but redo if variables change. I can add my code but it's a bit long. If anyone wants to look at it, I willing to post it.

PaulS

Quote
When my robot is centered(variable x) to the object, and when my distance is equaled to some amount(variable d). I would like it to drop my arm() function, do it once but redo if variables change.

Are you asking for permission or help? If you want permission, go ahead.

If you need help, you need to define what you need help with. Calling the function when x is equal to some value and d is equal to some value is easy:
Code: [Select]
if(x == SomeValue && d == SomeOtherValue)
{
   arm();
}


To ensure that arm() only gets called once:

Code: [Select]
bool armDone = false;

void loop()
{
   // Some stuff

   if(x == SomeValue && d == SomeOtherValue && !armDone)
{
   arm();
   ardMode = true;
}


At some point in the code, you will need to set armDone back to false, or else the arm will never move again.

Go Up