tone programming

Hy guy,

I have a question about one of my first programm with arduino. I have seen a lot of tutorials for beginner, but nothing about my problem. So maybe someone of you can help me.
What i want to do, is, to make a programm, that will play tones on a piezo from 300 hz - 14000hz and this again and again.
But the only thing that i can hear is only one tone, like there is only one frequenz playing. Maybe the code is playing so fast, that i can´t hear the change between the frequenz.
And i don´t know if my code is a good solution for my "project". Maybe someone can tell me a better way.

My code:

void setup(){
  pinMode(11, OUTPUT);
       }
void loop()
{   int frequenz=300;

    if (frequenz<14000);
  {
      tone(11, frequenz+1);
  }
    if (frequenz>14000);
  {
      int frequenz=300;
  }
}

Thanks for your help

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool. I recommend you to use the standard IDE instead.

Okay, sorry. I will do that next time..

You might find it works better if you call noTone() to switch the existing note off before sending each new tone() frequency. And it will be running fast. Try a small delay after each tone(), say 1/10th of a second (delay(100)).

Steve

Thanks for your answer, i made a delay after the "if" declaration but it did´nt regocnize the delay.
So there is a issue in the program that i don´nt know.

For clarity I would do some thing along the lines of:

tone(11,...);
delay(500);
noTone(11);
delay(500);

which is one of the few occasions I would advocate using delay()!

What you have written, with comments:

void setup() {
  pinMode(11, OUTPUT);
}

void loop()
{
  int frequenz = 300;   // This creates a local variable named 'frequenz' and sets it to 300

  if (frequenz < 14000);   // 300 is always <14000 so this executes the null statement: ';'
  
  {
    tone(11, frequenz + 1);   // This plays the tone 301 Hz
  }
  
  if (frequenz > 14000);  // 300 is never >14000 so the null statement ';' doesn't get executed

  
  {
    int frequenz = 300;  // This creates a NEW variable that only exists between these brackets and is not used
  }
  
}

This is what you apparently intended to do:

void setup() {
  pinMode(11, OUTPUT);
}

int frequenz = 300;   // This creates a GLOBAL variable named 'frequenz' and initializes it to 300

void loop() {
  if (frequenz < 14000) {
    tone(11, frequenz);   // This plays the tone
    frequenz = frequenz + 1;  //  frequenz += 1;   and   frequenz++;  are shortcuts that would do the same thing
  }
  else {
    frequenz = 300;  // Set the global variable back to 300
  }
}