Hello All, been working on a small project with two mini servos.
The Joystick controls both servos, left and right. When in the neutral position, the x-axis servo trembles. That is to say it seems like it is getting input from the Joystick and it seems to tremble back and forth a little. This is undesirable as I want the laser to sit perfectly still. Below is a link so you can see and hear it in a video.
Also here is the code.
Any light anyone could shed would be greatly appreciated!
#include <SoftwareServo.h>
SoftwareServo myservo;
SoftwareServo myservo1; // object to control a servo
int x,y,z;
boolean light_on = false;
int reading = 0;
void setup()
{
myservo.attach(2);
myservo1.attach(1);
// Serial.begin(9600);
pinMode(3, OUTPUT); //pin 3 digital laser out (black to red BB)
pinMode(7, INPUT); // z COM port white to grey com port 7
}
void loop()
{
if(light_on == true)
{
digitalWrite (3, HIGH); // turn the light on!
}
if(light_on == false) // turn the light off!
{
digitalWrite (3, LOW);
}
reading = digitalRead(7); // check the value of the z input on the joystick.
if (reading == 1)
{
light_on = ! light_on;
}
reading = 0;
//=================
x = analogRead(0);
x = map(x, 0, 1023, 0,180 );
y = analogRead(1);
y = map(y, 0, 1023, 0, 179);
myservo.write(x);
myservo1.write(y);
delay(15);
SoftwareServo::refresh();
}