Getting rid of delays in code that's not weaved and can be called over and over.
//SMS sending function un-delayed
void sms(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.print( F( "AT+CMGD=1,4\n\r" )); // Delete all messages so there are no conflicts with accidentally unread or stored SMS
procState = 1; // run case 1 next time
waitTimer = 1000;
startTimer = millis();
break;
case 1 :
mySerial.println("AT+CMGS=\"" + phone + "\""); // send to desired phone
procState = 2; // run case 2 next time
waitTimer = 1000;
startTimer = millis();
break;
case 2 :
mySerial.print("\"" + text + "\""); // containing desired text
procState = 3; // run case 1 next time
waitTimer = 1000;
startTimer = millis();
break;
case 3 :
mySerial.print((char)26); // signals end of text message
procState = 0; // run case 0 next time
waitTimer = 2000;
startTimer = millis();
break;
}
}
Some of the rest of the sketch should be re-arranged to get the delays out.
BTW, in small memory environments you should avoid using String variables.