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);
}