IF and TONE do not mix!

This statement makes a sound
foo...
tone(HO8, hertz);
bar...

this one does not:
foo...
tone(HO8, hertz);
if (target == 2) tone(AM7, hertz);
bar...

HO8 is 2 speakers and a horn, thru the obligatory resistor. AM7 is that same horn, through an amplifier. Why in world does that never make a tone? Regardless of target value. I comment out the second line and it works fine, but not for my purposes down road...

Here is the function:

void beep(int flag, int targetSet) {
  int i;

  // Beep II Function
  /*
    if (hookedUp == 0) {
    noTone(A0);
    noTone(A1);
    return;
    }
  */
  if (flag == -1) {
    noTone(A0);
    noTone(A1);
    eventSound = "";
    eventName = "";
  } //STOP
  if (flag == 0) {
    //Check if need to continue
    if (millis() - beepMS > beepLen) {
      noTone(A0);
      noTone(A1);
      i = iBeep;
      i = i + 1;
      targetSet = target; //Keep Target same
      flag = 1;
    }
  }

  // Continue

  if (flag == 1) {
    target = targetSet;
    if (eventName != "") {
      eventSound = eventName;
    }
    noTone(A0);
    noTone(A1);
    for (i; i < beepArrSize; i++) {
      if (eventSound == aEventName[i]) {
        iBeep = i;
        beepLen = aBeepLen[i];
        hertz = aBeepHertz[i];
        beepMS = millis();
        Serial.print("BeepLen: ");
        Serial.println(beepLen);
        Serial.print("Hertz:");
        Serial.println(hertz);

        tone(HO8, hertz);
        if (target == 2) tone(HO8, hertz); //For some reason this prevents beeps
        i = 100;
      }
    }
  }
}

Where and how is target declared and its value set ?
If only you had posted your complete program ...

From the tone() reference page:

Only one tone can be generated at a time. If a tone is already playing on a different pin, the call to tone() will have no effect.

And why do you keep sending notone() to two pins, neither of which seem to be the solitary pin that ever sees a tone() ?

Steve

Try ToneLibrary (available in the Library Manager).

oqibidipo:
Try ToneLibrary (available in the Library Manager).

Thanks this looks awesome. It doesn't rely on the built in tone function.

HO8 is 2 speakers and a horn, thru the obligatory resistor. AM7 is that same horn, through an amplifier.

So, the HO8 pin is electrically connected to the output of an audio amplifier through a resistor? And it's in pinMode OUTPUT? Then either the audio from the amplifier will be grounded through the arduino via that resistor (if HO8 is LOW), or you will be jamming lord knows how many watts of audio into the ardiuno's 5v rail (if HO8 is HIGH).

It's not going to work out well, is what I am saying.