Hello All!
So I'm having a little trouble understanding digital vs analog servos. I've got 4 set up in the following configuration:
HS-755HB - Potentiometer
HS-985MG - Push Button
HS-5645MG - Push Button
HS-5645MG - Push Button
They're all attached to 5V external power and the same arduino with the below code
#include <Servo.h>
Servo hs755hb; // Positioning Servo
Servo hs985mg; // Firing Servo 1
Servo hs5645mg1;// Firing Servo 2
Servo hs5645mg2;// Firing Servo 3
const int buttonPin1 = 13; // the number of the pushbutton pin
const int buttonPin2 = 12; // the number of the pushbutton pin
const int buttonPin3 = 8; // the number of the pushbutton pin
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0; // variable for reading the pushbutton status
int buttonState3 = 0; // variable for reading the pushbutton status
int pos2 = 0; // laser servo position variable
int pos3 = 0; // laser servo position variable
int potpin0 = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
{
hs755hb.attach(6); // laser servo PWM control - Arduino pin 6
hs985mg.attach(9); // laser servo PWM control - Arduino pin 9
hs5645mg1.attach(10); // laser servo PWM control - Arduino pin 10
hs5645mg2.attach(11); // laser servo PWM control - Arduino pin 11
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
//Store Servos in upright position
hs985mg.write(90); // 43ms delay for sweep
for(pos2 = 0; pos2 < 90; pos2 +=1) // sweep from 0 to 90 degrees in steps of 1
{
hs5645mg1.write(pos2); // sweep
delay(43); // 43ms delay for sweep
}
for(pos3 = 0; pos3 < 90; pos3 +=1) // sweep from 0 to 90 degrees in steps of 1
{
hs5645mg2.write(pos3); // sweep
delay(43); // 43ms delay for sweep
}
}
void loop()
{
//Hitec HS-755HB Positioning Servo
val = analogRead(potpin0); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
hs755hb.write(val); // sets the servo position according to the scaled value
delay(56); // waits for the servo to get there
//Hitec HS-985MG Firing Servo
buttonState1 = digitalRead(buttonPin1);
if (buttonState1 == HIGH)
{
hs985mg.write(20); // sweep start position
}
//Hitec HS-5645MG Firing Servo
buttonState2 = digitalRead(buttonPin2);
if (buttonState2 == HIGH)
{
for(pos2 = 90; pos2 > 20; pos2 -=1) // sweep from 0 to 120 degrees in steps of 1
{
hs5645mg1.write(pos2); // sweep start position
delay(43); // 15ms delay for sweep
}
}
//Hitec HS-5645MG Firing Servo
buttonState3 = digitalRead(buttonPin3);
if (buttonState3 == HIGH)
{
for(pos3 = 90; pos3 > 20; pos3 -=1) // sweep from 0 to 120 degrees in steps of 1
{
hs5645mg2.write(pos3); // sweep start position
delay(43); // 15ms delay for sweep
}
}
}
My question is this: The Hitec HS-755HB has no issue responding promptly to the potentiometer, the Hitec HS-985MG has no problems responding to the button press, but the two Hitec HS-5645MG just sit there like bumps on logs and make tiny jerky movements or none at all!
Thoughts on how my code might be written better or on why these servos are responding the way I expect them to?
Thanks!
Signed,
Frustrated and Confused.