I'm attempting to create a simple code for a servo that will attach to a camera slider.
I have a joystick connected and when I press UP or DOWN, the motor will turn but ONLY a little bit. It won't continuously turn.
The servo I'm using is a HiTec Deluxe HS-422
I'm a complete noob.
I tried to change int ServoV_Max = 180; to a higher number and it would rotate further but I can't simply get the motor to go in one direction forever until I release the joystick. Then I'd like it to go in the other direction when I move the joystick in the opposite direction.
Here's my current code:
// letsarduino.com
// (thumbstick) + Arduino
#include <Servo.h>
int ServoHorizontalPin = 3;
int ServoVerticalPin = 4;
int HorizontalPotPin = A0;
int VerticalPotPin = A1;
int ServoH_Min = 0;
int ServoH_Max = 180;
int ServoV_Min = 0;
int ServoV_Max = 180;
Servo HorizontalServo;
Servo VerticalServo;
int HorizontalPotValue;
int HorizontalServoPosition;
int VerticalPotValue;
int VerticalServoPosition;
void setup()
{
HorizontalServo.attach(ServoHorizontalPin);
VerticalServo.attach(ServoVerticalPin);
}
void loop()
{
HorizontalPotValue = analogRead(HorizontalPotPin);
VerticalPotValue = analogRead(VerticalPotPin);
HorizontalServoPosition = map(HorizontalPotValue, 0, 1023, ServoH_Min , ServoH_Max);
VerticalServoPosition = map(VerticalPotValue, 0, 1023, ServoH_Min , ServoH_Max);
HorizontalServo.write(HorizontalServoPosition);
VerticalServo.write(VerticalServoPosition);
delay(20);
}
ANY help is appreciated!