issues with functions

I'm currently using my arduino to control four actuators to move in different directions for pre-configured motions. Individually, my functions work, but when i try to demo the complete range of motions, it will only ever do my 'nuetral' function and one other function. This is puzzeling to me, because the code in these functions is nearly identical besides variable name changes and pot values. Is there a limit to the amount of functions that can be called? Am i missing something incredibly obvious (so tired). I'm attaching my code below, and how i'm trying to call it. Each function works correctly by itself, but when i try to do one after another (unless it is immediately following my nuetral function) it just stops doing anything.

void loop ( )
{
//64 will stop the motor 1
//192 is stop for motor 2
//All MC's active to set a nuetral position  
    digitalWrite(MC1, LOW);  
    digitalWrite(MC2, LOW);
    // there appears to be a bug where it will only do two functions in a row. All functions work individualy
   Nuetral();

   LeanLeft();

  LeanRight();

}

Breaking it up into snippets:

Nuetral code (only showing the first actuator's test/adjustment to save space, and the final global position check):

void Nuetral( void )
{


  boolean nuetral = false; //all actuators are in nuetral position
  boolean nuetral1 = false; // checking actuator 1 in position
  boolean nuetral2 = false; // checking actuator 2 in position
  boolean nuetral3 = false; // checking actuator 3 in position
  boolean nuetral4 = false; // checking actuator 4 in position
//64 will stop the motor 1
//192 is stop for motor 2
//All MC's active to set a nuetral position  do i need to worry about this? 
// I'm setting the MC's with ever loop check
  while (!nuetral)
  { 
    // Reading in values for actuator position, lower is more extended
    Actuator1Value = analogRead(Actuator1);
    Actuator2Value = analogRead(Actuator2);
    Actuator3Value = analogRead(Actuator3);
    Actuator4Value = analogRead(Actuator4);
    // checking and adjusting actuator 1
    if (Actuator1Value >= 615)
    {
      digitalWrite(MC1, HIGH);  
      digitalWrite(MC2, LOW); 
      SaberSerial.write(byte(SABER_MOTOR2_FULL_FORWARD));    
    }
    if (Actuator1Value <= 585)
    {
      digitalWrite(MC1, HIGH);  
      digitalWrite(MC2, LOW); 
      SaberSerial.write(byte(SABER_MOTOR2_FULL_REVERSE));
    }
    if ((Actuator1Value > 585) && (Actuator1Value < 615))
     nuetral1 = true;
    
     
    // checking to make sure all actuators are in right position before leaving loop.  
    if (nuetral1 && nuetral2 && nuetral3 && nuetral4)
    {
      nuetral= true;
    }      
  }
}

Leaning left:

void LeanLeft( void )
{

  boolean leaningLeft = false; //all actuators are in  position
  boolean leaningLeft1 = false; // checking actuator 1 in position
  boolean leaningLeft2 = false; // checking actuator 2 in position
  boolean leaningLeft3 = false; // checking actuator 3 in position
  boolean leaningLeft4 = false; // checking actuator 4 in position
//64 will stop the motor 1
//192 is stop for motor 2
//All MC's active to set a nuetral position  do i need to worry about this? 
// I'm setting the MC's with every loop check
  while (!leaningLeft)
  { 
    // Reading in values for actuator position, lower is more extended
    Actuator1Value = analogRead(Actuator1);
    Actuator2Value = analogRead(Actuator2);
    Actuator3Value = analogRead(Actuator3);
    Actuator4Value = analogRead(Actuator4);
    // checking and adjusting actuator 1
    if (Actuator1Value >= 1115)
    {
      digitalWrite(MC1, HIGH);  
      digitalWrite(MC2, LOW); 
      SaberSerial.write(byte(SABER_MOTOR2_FULL_FORWARD));    
    }
    if (Actuator1Value <= 1095)
    {
      digitalWrite(MC1, HIGH);  
      digitalWrite(MC2, LOW); 
      SaberSerial.write(byte(SABER_MOTOR2_FULL_REVERSE));
    }
    if ((Actuator1Value > 1095) && (Actuator1Value < 1115))
     leaningLeft1 = true;
    
    
      // checking and adjusting actuator 2
    if (Actuator2Value >= 55)
    {
      digitalWrite(MC1, HIGH);  
      digitalWrite(MC2, LOW); 
      SaberSerial.write(byte(SABER_MOTOR1_FULL_FORWARD));    
    }
    if (Actuator2Value <= 35)
    {
      digitalWrite(MC1, HIGH);  
      digitalWrite(MC2, LOW); 
      SaberSerial.write(byte(SABER_MOTOR1_FULL_REVERSE));
    }
    if ((Actuator2Value > 35) && (Actuator2Value < 55))
     leaningLeft2 = true;     
     
    
    // checking and adjusting actuator 3
    if (Actuator3Value >= 55)
    {
      digitalWrite(MC1, LOW);  
      digitalWrite(MC2, HIGH);
      SaberSerial.write(byte(SABER_MOTOR1_FULL_FORWARD));    
    }
    if (Actuator3Value <= 35)
    {
      digitalWrite(MC1, LOW);  
      digitalWrite(MC2, HIGH);
      SaberSerial.write(byte(SABER_MOTOR1_FULL_REVERSE));
    }
    if ((Actuator3Value > 35) && (Actuator3Value < 55))
     leaningLeft3= true;  
    
    
    // checking and adjusting actuator 4
    if (Actuator4Value >= 1115)
    {
      digitalWrite(MC1, LOW);  
      digitalWrite(MC2, HIGH);
      SaberSerial.write(byte(SABER_MOTOR2_FULL_FORWARD));    
    }
    if (Actuator4Value <= 1095)
    {
      digitalWrite(MC1, LOW);  
      digitalWrite(MC2, HIGH);
      SaberSerial.write(byte(SABER_MOTOR2_FULL_REVERSE));
    }
    if ((Actuator4Value > 1095) && (Actuator4Value < 1115))
     leaningLeft4 = true;       
    
    // checking to make sure all actuators are in right position before leaving loop.  
    if (leaningLeft1 && leaningLeft2 && leaningLeft3 && leaningLeft4)
    {
      leaningLeft= true;
    }      
  }

}

Leaning right:

void LeanRight(void)
{

  boolean leaningRight  = false; //all actuators are in  position
  boolean leaningRight1 = false; // checking actuator 1 in position
  boolean leaningRight2 = false; // checking actuator 2 in position
  boolean leaningRight3 = false; // checking actuator 3 in position
  boolean leaningRight4 = false; // checking actuator 4 in position
//64 will stop the motor 1
//192 is stop for motor 2
// I'm setting the MC's with every loop check
  while (!leaningRight)
  { 

    // Reading in values for actuator position, lower is more extended
    Actuator1Value = analogRead(Actuator1);
    Actuator2Value = analogRead(Actuator2);
    Actuator3Value = analogRead(Actuator3);
    Actuator4Value = analogRead(Actuator4);    
    // checking and adjusting actuator 1
    if (Actuator1Value >= 55)
    {
      digitalWrite(MC1, HIGH);  
      digitalWrite(MC2, LOW); 
      SaberSerial.write(byte(SABER_MOTOR2_FULL_FORWARD));    
    }
    if (Actuator1Value <= 35)
    {
      digitalWrite(MC1, HIGH);  
      digitalWrite(MC2, LOW); 
      SaberSerial.write(byte(SABER_MOTOR2_FULL_REVERSE));
    }
    if ((Actuator1Value > 35) && (Actuator1Value < 55))
     leaningRight1 = true;
    
    
      // checking and adjusting actuator 2
    if (Actuator2Value >= 1115)
    {
      digitalWrite(MC1, HIGH);  
      digitalWrite(MC2, LOW); 
      SaberSerial.write(byte(SABER_MOTOR1_FULL_FORWARD));    
    }
    if (Actuator2Value <= 1095)
    {
      digitalWrite(MC1, HIGH);  
      digitalWrite(MC2, LOW); 
      SaberSerial.write(byte(SABER_MOTOR1_FULL_REVERSE));
    }
    if ((Actuator2Value > 1095) && (Actuator2Value < 1115))
     leaningRight2 = true;     
     
    
    // checking and adjusting actuator 3
    if (Actuator3Value >= 1115)
    {
      digitalWrite(MC1, LOW);  
      digitalWrite(MC2, HIGH);
      SaberSerial.write(byte(SABER_MOTOR1_FULL_FORWARD));    
    }
    if (Actuator3Value <= 1095)
    {
      digitalWrite(MC1, LOW);  
      digitalWrite(MC2, HIGH);
      SaberSerial.write(byte(SABER_MOTOR1_FULL_REVERSE));
    }
    if ((Actuator3Value > 1095) && (Actuator3Value < 1115))
     leaningRight3= true;  
    
    
    // checking and adjusting actuator 4
    if (Actuator4Value >= 55)
    {
      digitalWrite(MC1, LOW);  
      digitalWrite(MC2, HIGH);
      SaberSerial.write(byte(SABER_MOTOR2_FULL_FORWARD));    
    }
    if (Actuator4Value <= 35)
    {
      digitalWrite(MC1, LOW);  
      digitalWrite(MC2, HIGH);
      SaberSerial.write(byte(SABER_MOTOR2_FULL_REVERSE));
    }
    if ((Actuator4Value > 35) && (Actuator4Value < 55))
     leaningRight4 = true;       
    
    // checking to make sure all actuators are in right position before leaving loop.  
    if (leaningRight1 && leaningRight2 && leaningRight3 && leaningRight4)
    {
      leaningRight= true;
    }      
  }
}

i
If i were to call the nuetral, the leanleft, then leanright, it would only perform the first two items. If i were to just call leanleft and leanright, it would only do leanleft.

Sorry for the massive post. Any insights would be appreciated.

That is not how you spell 'neutral'.

Those replicated chunks of code are crying out to be made into functions. This would reduce the size of your sketch and the potential for copy/paste issues by about a factor of four.

It's not obvious what sequence of actions you intend to take for each motor when you do left, neutral, right. I can see code that appears to be moving the motors towards the mid position in 'Nuetral()' but I don't see where you stop the motors. Since you're changing the output state of MC1 and MC2 at the start of the movement I sort of expected that you'd change them back at the end, but I don't see that.

My suggestion is that you put this sketch to one side and write another much simpler sketch that just deals with one actuator and does nothing but the sequence of I/O operations to drive that actuator through a sequence of positions. Once you are clear what needs to be done to drive the actuator, you can change the original sketch as necessary to implement that or (better) chuck this 'mark 1' sketch away and write another one that uses the same code for all four actuators.

How fast does the actuators move? I see no time given to allow them to reposition before you restart the loop, re-read the analog pins for new position and presumably bang another serial cmd out.

Nevertheless I'd agree with PeterH, get one working as intended first. Then you can reuse the function for each actuator passing the actuator number you wish to modify. do a case check for what the pot values should be dependent on what actuator number was sent.

great advice, i'll work on it and repost when i can.

Sounds like your problem is that leanright doesn't run, no thet it will only execute 2 functions, because when you eliminate Neutral then only 1 function executes...

In this function:

void LeanLeft( void )

you have this test:

    if ((Actuator1Value > 1095) && (Actuator1Value < 1115))
     leaningLeft1 = true;

The test examines the result of an analogRead to see if it's bigger than 1095. Every Arduino that I'm familiar with has a 10-bit ADC, with a maximum reading of 1023. So, as I see it, this test will always fail, and the boolean will never be set to "true."

Later, there's this code:

    if (leaningLeft1 && leaningLeft2 && leaningLeft3 && leaningLeft4)
    {
      leaningLeft= true;
    }

This test will always fail, too, because the first argument to "&&" is always false. The function never exits its "while" loop, because "leaningLeft" is never true. The next function isn't executed, because the program never exits this one.

The same thing happens elsewhere in this function, and in the other "Lean" function as well.

Check your math and see if you're really looking for an analog reading bigger than 1023. If you are, then you'll need to change something in your potentiometer circuit. I'd suspect that the easiest change would be to connect the fixed terminals of your potentiometer between 0V and 5V, rather than maybe the motor supply voltage, to make sure that the wiper voltage stays in the range of the ADC, and then recalculate your limits.

To quickly verify, I'd recommend printing a message between the calls to the various functions - something like:

  Serial.println("Finished LeanLeft.");

If it doesn't print the message, then it got stuck in the function.

wow.. surprised i missed that. Checking for incorrect values was my problem. Sorry to even bother you guys with that. I think one of my main problems was using so many different functions when i could have used one.

Thanks for all the advice guys. I'll keep simplification in mind in the future. Seems like it made it harder for me to troubleshoot. I really appreciate the advice, and will take it into account. This is my first time coding, as well as using this forum. Thanks for the good experience.