More effective way to create an Oscillating Counter?

Hey There,

I want to make an oscillating counter so that it sweeps between 25k and 50k. Is there a more effective way to do this?

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

void loop() { 

   unsigned int freq1 = 25000;      //should range between 25kHz and 50kHz
   tone(10, freq1);

  
     for (int i=0; i <= 25000; i++){
      freq1 = freq1 + 1;
      delay(1);
   } 
     for (int i=0; i <= 25000; i++){
      freq1 = freq1 - 1;
      delay(1);
   } 

     

}
void loop() {

   static unsigned int freq1 = 25000;      //should range between 25kHz and 50kHz
   tone(10, freq1);

cterjesen, your code does not change the pins frequency anymore after setting it to 25kHz.

lg, couka

How do I sweep the frequency between 25kHz and 50kHz?

cterjesen:
How do I sweep the frequency between 25kHz and 50kHz?

You could try actually outputting a tone from your original program each time you change the value of freq1