Functions with string parameters
Just change
void sendSMS()
to
void sendSMS(const String& thisIsAString)
You can then access the parameter inside the function with
thisIsAString
.No, you do not need a prototype.
I'd say to never use String again. When code gets bigger and memory usage will be critical you'll hit a dead-end. I know it's more convenient, but give char arrays a shot. Something like:
bool sendSMS(int remoteNumber, char *finalstr){
bool isFinished = 0;
sms.beginSMS(remoteNumber);
for (int i=0;i<sizeof(finalstr);i++){
sms.print(finalstr);
}
sms.endSMS();
lcd.setCursor(0, 0);
lcd.print("Message sent!");
delay(10000);
isFinished = 1;
return isFinished;
}
I changed the function to bool. It means that you can use it inside an if statement, where you would want it completed before continuing with your code.
You will need to allocate memory yourself for the array; declare it like this:
char stringArray[33] = {'\0'};
Here, I allocate 32 bytes for data and one additional byte for the character that means "end of string" (it's that \0).