I have a servo and whenever I start my code it jumps to 0 immediately. Is there any way to make it go to 180 instead? If there isn't I'll just live with it.
I've tried these things.
Try this code. I have tested it on my Uno with a little servo. It moves to 180 at boot and pauses there for 3 seconds before starting the sweep example on my set up. Mind the servo pin number.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.write(180);
myservo.attach(4); // attaches the servo on pin 9 to the servo object
delay(3000);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
}
}