[SOLVED]Six servos robot arm homing function going very slow

Hi all, i am trying to make a 6DOF robot arm.
So far so good, I got all the servos to do what I want, but this function attached doesn't work as expected; The motors should returns to 90° when I press the button, and they do, but painfully slow...

I cutted the sketch to include just this function for the sake of readability; Please note that the other function (not attached) works the same by incrementing the angle of a servo by one degree every millisecond given the corresponding button is pressed.
While that one works good and with the right timing, this one moves like 2 degree every second.

Any help appreciated,
Thanks in advance!

Servo joints[7];
const byte homeAngles[7] = {0, 90, 90, 90, 90, 90, 90};
byte jointAngles[7] = {0, 90, 90, 90, 90, 90, 90};
byte resetAxis = 1;
void loop() {
   if(homeButtonStatus == HIGH) {
     resetPosition();
   }
}
void resetPosition() {
 if (jointAngles[resetAxis] != homeAngles[resetAxis]) {
   if (jointAngles[resetAxis] < homeAngles[resetAxis]) {
     joints[resetAxis].write(jointAngles[resetAxis]++);
     resetAxis++;
   } else {
     joints[resetAxis].write(jointAngles[resetAxis]--);
     resetAxis++;
   }
 } else {
   resetAxis++;
 }
 if (resetAxis == 7) {
   resetAxis = 1;
 }

Edit: It was slow because of too many lcd prints.

Your code doesn't compile, so it is hard to comment on how it should perform.

GrooveFlotilla:
Your code doesn't compile, so it is hard to comment on how it should perform.

You're right, i only included the troubled part...

Please, try the sketch i just attached!

6AxisArm.zip (64.9 KB)

  for (int i = 1 ; i < 7 ; i++) {
    int minPulse;
    int maxPulse;
    switch (i) {
      case 1:
      minPulse = 740;
      maxPulse = 2350;
      break;
      case 2:
      minPulse = 690;
      maxPulse = 2320;
      break;
      case 3:
      minPulse = 710;
      maxPulse = 2310;
      break;
      case 4:
      minPulse = 620;
      maxPulse = 2230;
      break;
      case 5:
      minPulse = 525;
      maxPulse = 2450;
      break;
      case 6:
      minPulse = 625;
      maxPulse = 2655;
      break;
    }
    joints[i].attach(i+1, minPulse, maxPulse);

Why do you use a for loop when every iteration does something different?

Comment out all that writing to the LCD. Does your program speed up?

PaulS:
Why do you use a for loop when every iteration does something different?

I used the for loop to assign the servos to their pins, then later added the switch to change the pulse length... Guess it could be just written straight, thanks for the input!

PaulS:
Comment out all that writing to the LCD. Does your program speed up?

Commenting that worked! But why does it clog the execution so bad? The other function does just the same... I wonder why.

Thanks a lot, i would have never figure it out!

You could try a I2C LCD backpack which would be much quicker. The LCD is only able to handle so much clock speed, and I2C is exponentially faster. The backpack is just another microcontroller which handles the actual writing to the LCD.

You could try a I2C LCD backpack which would be much quicker. The LCD is only able to handle so much clock speed, and I2C is exponentially faster

Except when you use an I/O extender I2C LCD in four bit mode, which could be much slower than a parallel eight bit mode LCD.

Isaac96:
You could try a I2C LCD backpack which would be much quicker. The LCD is only able to handle so much clock speed, and I2C is exponentially faster. The backpack is just another microcontroller which handles the actual writing to the LCD.

I'm already using it, it's a life saver! Don't know if it's in 4bit though