Using millis to send different messages

Hi!
Is there any way to use the same millis function to send four different messages. To clarify if the time has passed millis sends a Serial.println message then the next instance the time has passed millis could send the second message then the third and fourth and then start with number one again. By just using the same millis function so each message would have the same time "delay"

Thanks in advance :slight_smile:

It would be straightforward to write a function, that at regular intervals (timed using the millis() function) would send send one of four different messages, cyclically.

Is that what you want to do?

Put the 4 messages in an array of chars
Add 1 to a counter when the period ends
Use the modulo operator (%) and the counter value to derive a number between 0 and 3
Use the derived number to pick the appropriate message

Serial.println(messages[counter % 4]);

UKHeliBob:
Put the 4 messages in an array of chars
Add 1 to a counter when the period ends
Use the modulo operator (%) and the counter value to derive a number between 0 and 3
Use the derived number to pick the appropriate message

Serial.println(messages[counter % 4]);

That can’t possibly work, unless each message is only one character long.

That can’t possibly work, unless each message is only one character long.

You are right. I expressed the solution badly but the basic idea works.

An example

char * messages[] = {"zero", "one", "two", "three"};

void setup()
{
  Serial.begin(115200);
  for (int x = 0; x < 12; x++)
  {
    Serial.println(messages[x % 4]);
  }
}

void loop()
{
}