Need help with processing+arduino serial

Hi guys! I'm doing a project for school and encountered a situation that I can't figure out.
Please bare in mind that my programming skills are on the low end of the scale.
What my system does (on the arduino side) is to generate different PWM signals that drive a DC motor. The processing acts as an interface.

Seperatly both parts do what I want, but when I finally tried everything together I encountered a situation: my motor doesn't stop.
When I choose one of the paths (in processing) it will start the the pwm signal I want, but when I try to leave or change said signal it gets stuck and the motor doesn't stop.

PVector[] vecsFisiologico = new PVector[11];
PVector[] vecsBisferiens = new PVector[13];
int currentCurvePointFisiologico;
int currentCurvePointBisferiens;

import processing.serial.*;
Serial myPort;
String myText="";
int pulso = -1;

void setup() {
  size(900, 900);
  setPointsFisiologico();
  setPointsBisferiens();
  smooth();
  frameRate(150);
  
  myPort = new Serial(this, "COM3", 115200);
  myPort.bufferUntil('n');
}

void serialEvent (Serial myPort){
myText = myPort.readStringUntil('n');
}

void draw() 
{
  background(100,255,100);

  switch(pulso) 
  {
  case -1: // difficult selection mode
    text("pulso a reproduzir", 10, 30);
    text("1, 2 ou 3 ?", 10, 50);
    pushStyle();
    fill(255, 204, 40);
    rect(30, 70, 20, 20);
    rect(60, 70, 20, 20);
    rect(90, 70, 20, 20);
    popStyle();
    text("1", 36, 86);
    text("2", 66, 86);
    text("3", 96, 86);
    myPort.write('S');

    break;
    
  case 1:

     drawFisiologico();
     rect(0, 0, 20, 20);
     myPort.write('A'); 

     break;

     
  case 2:
  
    drawBisferiens();
    rect(0, 0, 20, 20);
    myPort.write('B');
    
    break;
    
  case 3:
    // difficult level 3 stuff here
    break;
  }
  fill(0);
  text("Pulso = " + pulso, 10, 120);


}


public void mouseClicked() 
{
  
  
  if (pulso == -1) 
  {
    if (mouseX > 29 && mouseX < 51 && mouseY > 69 && mouseY < 91) 
    {
      pulso = 1;
    }
    else if (mouseX > 59 && mouseX < 71 && mouseY > 69 && mouseY < 91) 
    {
      pulso = 2;
    }
    else if (mouseX > 89 && mouseX < 101 && mouseY > 69 && mouseY < 91) 
    {
      pulso = 3;
    } 
  }
if (mouseX > 0 && mouseX < 21 && mouseY > 0 && mouseY < 21)
    {
          pulso = -1;
    } 

}

//from this point on is just the definition of the graphs, don't lose time :b

void drawFisiologico()
{
  drawShapeFisiologico();
  drawPointsFisiologico();
    if (frameCount % 20 == 0) 
    { 
      currentCurvePointFisiologico++;
    }
  drawCurvePointFisiologico(currentCurvePointFisiologico % (vecsFisiologico.length-3)); 
}
void setPointsFisiologico() 
{  
   vecsFisiologico[0] = new PVector(0, 600);
   vecsFisiologico[1] = new PVector(0, 600);
   vecsFisiologico[2] = new PVector(50, 600);
   vecsFisiologico[3] = new PVector(100, 318);
   vecsFisiologico[4] = new PVector(150, 120);
   vecsFisiologico[5] = new PVector(250, 352);
   vecsFisiologico[6] = new PVector(325, 300);
   vecsFisiologico[7] = new PVector(400, 350);
   vecsFisiologico[8] = new PVector(700, 559);
   vecsFisiologico[9] = new PVector(800, 600);
   vecsFisiologico[10] = new PVector(800, 600); 
}

void drawShapeFisiologico() {
  noFill();
  stroke(0);
  beginShape();
  for (int i=0; i<vecsFisiologico.length; i++) {
    curveVertex(vecsFisiologico[i].x, vecsFisiologico[i].y);
  }
  endShape();
}

void drawPointsFisiologico() {
  noStroke();
  fill(255, 0, 0);
  for (int i=1; i<vecsFisiologico.length-1; i++) {
    ellipse(vecsFisiologico[i].x, vecsFisiologico[i].y, 5, 5);
  }
}

void drawCurvePointFisiologico(int num) {
  noStroke();
  fill(0, 0, 255);
  float t = (frameCount % 20)/20.0;
  float x = curvePoint(vecsFisiologico[num].x, vecsFisiologico[num+1].x, vecsFisiologico[num+2].x, vecsFisiologico[num+3].x, t);
  float y = curvePoint(vecsFisiologico[num].y, vecsFisiologico[num+1].y, vecsFisiologico[num+2].y, vecsFisiologico[num+3].y, t);
  ellipse(x, y, 15, 15);
}

void drawBisferiens()
{
  drawShapeBisferiens();
  drawPointsBisferiens();
    if (frameCount % 20 == 0) 
    { 
      currentCurvePointBisferiens++;
    }
  drawCurvePointBisferiens(currentCurvePointBisferiens % (vecsBisferiens.length-3)); 
}
void setPointsBisferiens() 
{  
   vecsBisferiens[0] = new PVector(0, 600);
   vecsBisferiens[1] = new PVector(0, 600);
   vecsBisferiens[2] = new PVector(50, 600);
   vecsBisferiens[3] = new PVector(100, 318);
   vecsBisferiens[4] = new PVector(150, 100);
   vecsBisferiens[5] = new PVector(190, 350);
   vecsBisferiens[6] = new PVector(230, 150);
   vecsBisferiens[7] = new PVector(300, 450);
   vecsBisferiens[8] = new PVector(370, 350);
   vecsBisferiens[9] = new PVector(450, 400);
   vecsBisferiens[10] = new PVector(600, 500);
   vecsBisferiens[11] = new PVector(800, 600);
   vecsBisferiens[12] = new PVector(800, 600); 
}

void drawShapeBisferiens() {
  noFill();
  stroke(0);
  beginShape();
  for (int i=0; i<vecsBisferiens.length; i++) {
    curveVertex(vecsBisferiens[i].x, vecsBisferiens[i].y);
  }
  endShape();
}

void drawPointsBisferiens() {
  noStroke();
  fill(255, 0, 0);
  for (int i=1; i<vecsBisferiens.length-1; i++) {
    ellipse(vecsBisferiens[i].x, vecsBisferiens[i].y, 5, 5);
  }
}

void drawCurvePointBisferiens(int num) {
  noStroke();
  fill(0, 0, 255);
  float t = (frameCount % 20)/20.0;
  float x = curvePoint(vecsBisferiens[num].x, vecsBisferiens[num+1].x, vecsBisferiens[num+2].x, vecsBisferiens[num+3].x, t);
  float y = curvePoint(vecsBisferiens[num].y, vecsBisferiens[num+1].y, vecsBisferiens[num+2].y, vecsBisferiens[num+3].y, t);
  ellipse(x, y, 15, 15);
}
#include <TimerOne.h>
int motorPin = 9;
float PWMb;
int PWMb1;
float PWMd;
int PWMd1;

int data;
void setup() {
Timer1.initialize(40);
Serial.begin(115200);

}

void functionA()
{
      int y = 0;
      for(int y = 0; y <= 5; y = y + 1)
      {
        int x = 0;
        for(int x = 0; x <= 100; x = x + 1) {
          PWMd = 10 * x;
          PWMd1 = (int) PWMd;
          Timer1.pwm(motorPin, PWMd1);
          delay (10);
        }
     }
}
void functionB()
{
      int y = 0;
      for(int y = 0; y <= 5; y = y + 1)
      {
        int x = 0 ;
        for(int x = 0; x<= 196; x = x + 1) 
        {
          PWMb = 1000 * sin(0.016 * x);
          PWMb1 = (int) PWMb;
          Timer1.pwm(motorPin, PWMb1);
          delay (10);
      
       }
     }
}
void loop() 
{
if(Serial.available())
  {
    //data = Serial.read();
    char pulso = Serial.read();
    
    if (pulso == 'A')
      {
            functionA();
            delay(10);
            if (pulso == 'S'){ goto bailout;}
          }
    
    if (pulso == 'B'){ //onda sinusoidal
        functionB();
    }
    bailout:{
    Timer1.pwm(9,0);  
    }
 }
}

Thanks in advance! Any help is greatly appreciated

    if (pulso == 'A')
      {
            functionA();
            delay(10);
            if (pulso == 'S'){ goto bailout;}
          }

If pulso equals 'A', there isn't a snowball's chance in hell that it will also equal 'S'.

There is NO excuse for using goto.

ok, I see your point. I've made some changes on that front, but what I realized was that the problem is the fact that I'm sending way too much stuff via serial (unnecessary stuff) since on the switch on processing keeps sending char. What I wanted to do was to make my system wait for a char to come and maintain that state until a different char comes.

could you help me out?

What I wanted to do was to make my system wait for a char to come and maintain that state until a different char comes.

You need to separate receiving serial data from using the serial data that you receive.

If you expect to send 'A', 'B', and 'S', and see the changes immediately, you'll need to scrap that code and start over WITHOUT using any for loops or delay().