Hi everyone,
im playing with Paul Mcworther's lessons but struggel with lesson. An angle must be put in to the serial monitor then the servo must move to that position, my servo does that but goes back to 0 after a second.
Here is the code. Please assist.
#include <Servo.h>
int servoPin=9;
int servoPos=180;
Servo myServo;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
myServo.attach(servoPin);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Angle");
while (Serial.available()==0);{
At a guess, change the Line ending setting of the Serial monitor to "No Line Ending" otherwise the line ending character(s) will be interpreted as user input
I wonder if the Iced Coffee guy made a point of that in his video, or maybe he said in a previous lesson that he was going to set it that way for all time and so should the students.
I've only watched a handful of his lessons, and TBH I hit the skip-ahead button quite a bit - I prolly miss quite a few little things.
servoPos = Serial.parseInt();
Serial.print("moving servo to "); Serial.println(servoPos);
myServo.write(servoPos);
When strange things happen, sometimes throwing a print statement or two on in there can provide evidence and help point your investigations in one direction or another.
Try it before and after you fix the problem, if indeed we turn out to have identified what is the problem.