thanks for that yeah i do get servo noise what do i change to stop it
You need to change the value of the servo positions for one that the servo you are using accepts. (usually servos can handle 0º to 180º, but most of them are 1º to 160º)
You can do that by changing the value inside the ()
i will mark the place for you on the code:
Code:
#include <Servo.h>
Servo myservo;
Servo myservo1;
int val;
int val2;
int buttonState;
int servostatus = 0;
int switchPin =2;
int ledPin = 5;
void setup()
{
myservo.attach(9);
myservo1.attach(10);
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
buttonState = digitalRead(switchPin);
myservo.write(1); //<------------- edit the servo 1 position here
myservo1.write(160); //<------------- edit the servo 2 position here (aways the inverse of the 1st position)
}
void loop()
{
val = digitalRead(switchPin);
delay(10);
val2 = digitalRead(switchPin);
if (val == val2) {
if (val != buttonState) {
if (val == LOW) {
if (servostatus == 0) {
servostatus = 1;
myservo.write(0); //<------------- edit the servo 1 position here
myservo1.write(190); //<------------- edit the servo 2 position here (aways the inverse of the 1st position)
delay(1000);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(00);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(00);
// fading
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
delay(30);
}
}
else {
servostatus = 0;
digitalWrite(ledPin, LOW);
delay(15);
myservo.write(210); //<------------- edit the servo 1 position here
myservo1.write(0); //<------------- edit the servo 2 position here (aways the inverse of the 1st position)
}
}
}
buttonState = val;
}
}
The way your code is set you have 3 different positions for the same servos along the code, change it to the same positions, a position that your servos can handle, and try it out. (remeber that the servo 2 is the inverse of the servo 1)
Hope that can help you out.