Hi!
I need a little help with a servo.
What i want to do is that when i push a button, the servo goes from 0- 180 degrees.( in slow motion)
Than some delay, before it returns back to its starting position (0)
I hope someone understands me
My code till now looks like this :
int inputPin1 = 2;
#include <Servo.h>
Servo myservo; Â // create servo object to control a servo
        // a maximum of eight servo objects can be created
int pos = 0; Â Â // variable to store the servo position
void setup() {
pinMode(inputPin1, INPUT);
 myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
void loop(){
 if (digitalRead(inputPin1) == LOW)
 {
  myservo.write(0-180);
 }
}
Step 1: Make you program work so that the servo moves at full speed but with a delay between the movements.
Step 2: Replace Servo.h with VarSpeedServo.h and write by slowmove
-- or --
Step 2 alternative: Add the code from Servo Sweep mentioned by Zoomcat.
Step 3: Have a merry Christmas with your slow servo sweeper.
But anyway, you need to start with Step 1 and fix your program to do what you want (although just at full speed)
You are close… you have the logic for detecting the button press, you just need to fill in the logic to move the servo.
try replacing this line:
myservo.write(0-180);
with:
int deg;
for (deg = 0; deg <= 180; ++deg) { // go from 0 - 180
myserver.write(deg); // set the servo to that degree
delay(50); // bigger = slower sweep
}
for (deg = 180; deg >= 0; --deg) { // go from 180 - 0
myserver.write(deg); // same thing, but going down
delay(50);
}