360 Servo won't stop after setting it to 180 degrees then 90

Hi,
I'm trying to code a 360 SG90 servo but after typing 180 to the console, most of the cases when I type 90 to stop the servo, the console doesn't log the desired angle and the servo doesn't stop. This is the code:

#include <Servo.h>
const int servoPin = 6;
Servo servo;
int angle;

void setup() {
  Serial.begin(9600);
  servo.attach(servoPin);
  servo.write(angle);
}

void serialEvent(){
  if(Serial.available()){
    angle = Serial.readStringUntil('\r').toInt();
    servo.write(angle);
    Serial.println(angle);
  }
}

Any help is greatly appreciated.

To the best of my knowledge, 360 degree, or continuous, servos don't allow you to rotate to a specific position. They simply rotate faster or slower depending on the value written.

I know that. The problem is that if I type 180, so the servo moves clockwise, and then I type 90, to stop the servo, the arduino doesn't get the 90 I typed and it just continues moving clockwise.

My apologies.

Do you have any reason to believe that your particular servo stops when whatever pulse width corresponding to writing 90 is sent?

I modified a 180 degree servo, disconnecting the potentiometer from the shaft and locking it on 90 degrees. That makes the servo turn to either side if it isn't equal to 90. However, this isn't the focus of the problem. The problem is that after typing 180 to the console, it won't get-register any value anymore. If I reset the arduino, the console goes back to normal and I can type 0 and 90 freely, but after typing 180 it "locks".

Since I'm clearly not seeing the focus of the problem, as you put it, I'll just leave you with this much simpler test that came to mind.

#include <Servo.h>
const int servoPin = 6;
Servo servo;

void setup() {
   servo.attach(servoPin);
   servo.write(180);
   delay(3000);
   servo.write(90);
}

void loop() {
}

And with that, I'll wish you good luck in pinning down where and what the problem is.

Yeah, first thank you. English isn't my native language so I may have not explained well. Thank you anyways for the help!

I don't know how continuous servos are suppose to work but...

I wonder if the software library "crashes" when you feed it 180 degrees or more?

With the pot locked at 90 degrees I'd expect anything over 90 to rotate clockwise and anything less than 90 to rotate counter-clockwise.

Like I said, I don't know but it doesn't seem like there should be any difference between 95 degrees and 180 degrees it it thinks it's stuck at 90.

could you share the rest of your code e.g. loop()

could it be that when the first byte arrives over Serial it jumps into this event function and tries to read more bytes - readStringUntil() - which generates more events.

Warning: assumptions ahead.

Not worked with them, but I expect serialEvent() is to be handled as an interrupt routine, so it should be short and non blocking. If my assumption is right there should only be the fetching of the buffer from Serial and handle the new characters in loop() somewhere.