Help-piezoelectric speaker using Arduino chip kit

how do I make the following code repeat 5 times w a valid loop() command?

[code/code]

void setup() { Serial.begin(9600); Serial.println("Tone sending..."); //tone(pinfrequency,duration); tone(11,,2000,1500); delay(1500); Serial.println("Tone done"); }

void loop() { ??????

}

Specifically, which code do you want to repeat? It doesn't make sense to repeat setup(), and loop() already repeats an infinite number of times.

If you some of the code in setup() to repeat, look at the do/while, while, and for statements.

Assuming that it’s just the tone that needs repeating then:

for (int k=0; k<5; k++) {
  tone(11,2000,1500);
  delay(1500);
  }

That will only make a 7 1/2 second continuous tone, tone() is non blocking, it doesn’t stop and wait while the tone is being generated. Try this:

void setup() {
  // set the digital pin as output:
  pinMode(11, OUTPUT);
}
void loop()
{
  int duration = 1500, interval = 1000;
  for (int k=0; k<5; k++) {
    tone(11,2000);
    delay(duration);
    noTone(11);
    delay(interval);
  }
  while(1); // press reset button to repeat   
}