Interfacing GSM module code optimization

I had to deal with an health issue in the family, hence not being able to give this thread more attention.

I have now successfully tested GoForSmoke's code. I will test 6v6gt's, then implement in my project.

I still need to read more about Serial communication and using C language char arrays (instead of the String library), but meanwhile I'll share code that is working as it is.

Here's a small sketch to send an SMS through the M590E GSM module by pressing a button and without using delays:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 4); // RX, TX

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  9;      // the number of the LED pin

int buttonState = 0;         // variable for reading the pushbutton status

String text = "button send"; // type message to be sent
String phone = "+351xxxYYYzzz"; // receiver's number

boolean triggerSMS = false;

void setup() {

  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);

  // Open serial communications and wait for port to open:
  Serial.begin(38400);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(38400);
  mySerial.println("Hello, world?");
  
}

void loop() {

  // reads back and displays the response to the AT commands sent through the Serial Monitor
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }

  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
    triggerSMS = true; // button was pressed, send standard sms
  }

  if (triggerSMS == true) {
    Send( text, phone);
  }
}

void Send(String text, String phone) {

  static word startTimer, waitTimer;  // waitTimer > 0 causes the timer to run, good up to 65 second intervals
  static byte procState;

  if ( waitTimer > 0 )
  {
    if ( word( millis() ) - startTimer < waitTimer )      return;     // time is not up yet
    else waitTimer = 0; // and on to the switch-case
  }

  switch ( procState )
  {
    case 0 :
      mySerial.println("AT+CMGF=1"); // Set SMS Text Mode
      procState = 1;      //  run case 1 next time
      waitTimer = 2000;
      startTimer = millis();
      break;

    case 1 :
      mySerial.println("AT+CSCS=\"GSM\"");  // 
      procState = 2;      //  run case 2 next time
      waitTimer = 2000;
      startTimer = millis();
      break;

    case 2 :
      mySerial.println("AT+CMGS=\"" + phone + "\"");  // send to desired phone
      procState = 3;      //  run case 3 next time
      waitTimer = 2000;
      startTimer = millis();
      break;

    case 3 :
      mySerial.print("\"" + text + "\""); // containing desired text
      procState = 4;      //  run case 4 next time
      waitTimer = 2000;
      startTimer = millis();
      break;

    case 4 :
      mySerial.print((char)26); // signals end of text message
      procState = 0;      //  run case 0 next time
      waitTimer = 2000;
      startTimer = millis();
      triggerSMS = false;
      break;
  }
}