I want to get rid of the last character of the string every 2 seconds so it would be "hello jac" then "hello ja" and so on. How can I do this?
This is how you could do that. Avoid using String and putting the string constantconstants in program memory.
// A buffer for the message
const size_t MSG_MAX = 16;
char msg[MSG_MAX];
void setup()
{
Serial.begin(9600);
while (!Serial);
}
void loop()
{
static int len = 0;
// Check if it is time to create the initial message
if (len == 0) {
strcpy_P(msg, (const char*) F("hello"));
strcat_P(msg, (const char*) F(" jack"));
len = strlen(msg) - 1;
}
// Otherwise shorten the message
else {
msg[len--] = 0;
}
// And print current message
Serial.println(msg);
delay(2000);
}