Servo Issue

I was using TinkerCad circuits and was messing around with a servo and some code I wrote. Instead of the servo going to 10 degrees and then back to 0 it goes to 93 and stays there! Can anyone help? Is it my code or TinkerCad?

Sincerely,

Connor M.

My Code:

#include <Servo.h>
Servo servo_2;
int Waypoint1delay = 1000;
int ServoPOS = servo_2.read();

void setup()
{
ServoPOS = 0;
Serial.begin(9600);
servo_2.attach (2);
pinMode(9, OUTPUT);
}

void loop() {
digitalWrite(9,HIGH);
servopositions();
servopositions();

}

void servopositions() { // Position of rudder 0 = center
ServoPOS = servo_2.read();
Serial.println(ServoPOS);
delay(10);
}

void servomovement() { //Movement of rudder
servo_2.write(10);
delay(Waypoint1delay);
servo_2.write(0);
delay(1000);
}

Did you try

void loop() {
digitalWrite(9,HIGH);
servomovement()
servopositions();
 
}

?

There's no point defining a function servomovement() and then never using it.

Steve

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile: