Use tone (speaker) whit-out delay . Use tone whit mills()

Hello!

I am new i Arduino. I need to know how kan use mills() when i use tone/speaker . I have used delay and this is working but I need to do this whit-out delay. The condition is that the speaker has to sound 3 times (beep, beep, beep ) and then it does not have to sound more.

tone(speakerPin, 450,50);
delay(100);
tone(speakerPin, 450,50);
delay(100);
tone(speakerPin, 450,50);
delay(100);

How about you look at the very first post in this forum that is permanently pinned there?

scsc_9310:
Hello!

I am new i Arduino. I need to know how kan use mills() when i use tone/speaker . I have used delay and this is working but I need to do this whit-out delay. The condition is that the speaker has to sound 3 times (beep, beep, beep ) and then it does not have to sound more.

const byte TONE_PIN = 4;
const int ALARM_BEEP_1 = 4186;
const int ALARM_BEEP_2 = 4699;

const int ALARM_TONE_LENGTH = 200;
const int ALARM_TONE_PAUSE = 800;
const int ALARM_TONE_REPEAT = 6;

void setup()
{
}

void loop()
{
  alarmSound();
}

void alarmSound() {
  static unsigned long next = millis();
  static byte count = 0;
  if (millis() > next) {
    next += ALARM_TONE_LENGTH;
    count++;
    if (count == ALARM_TONE_REPEAT) {
      next += ALARM_TONE_PAUSE;
      count = 0;
    }
    tone(TONE_PIN, (count % 2) ? ALARM_BEEP_1 : ALARM_BEEP_2, ALARM_TONE_LENGTH);
  }
}

scsc_9310:
Thank You for you help, but the alarm / beep need to only repeat 3 times and then finish.

you need to understand the example, so modify it