I have an Arduino Uno and two Hi-tec servos (HS-40 & 5055 digital) that I'm using for a basic robot build. I'm trying to have one servo(HS-40) turn the head back and forth (left to right) slightly faster than the other servo (HS-5055) controlling the upper torso.
I would like to have each servo working at the same time but not at the same speed without waiting for one servo to complete its movement.
I tried a sketch with a delay of 45-50 which seems to work fine for the movement speed and 0-75 degrees is ideal for the head travel and 0-65 degrees for the torso travel. I would like to have this movement to be repeated continuously so the robot mimics like it is looking side to side or left to right naturally.
Please help as I tried many sketches but can't find one that works like this. I tried modifying other code but can't get them work. Any help will be greatly appreciated.
How do modify this code so just the second servo runs at 40 which will slow down just enough? Also this is not my code, but it's one that seems to be close to what I'm trying to do.
#include <Servo.h>
Servo servo1;
Servo servo2;
int i = 0;
void setup() {
servo1.attach(8);
servo2.attach(9);
}
void loop() {
for (i = 0; i < 70; i++) {
servo1.write(i);
servo2.write(i);
delay(50);
}
for (i = 70; i > 0; i--) {
servo1.write(i);
servo2.write(i);
delay(50);
}
}
servo1.write(2*i);