Problem while using "for" loop on a Buzzer

Hello,
Can someone help me troubleshooting this code:

int buzzer = 2;
int t = 250;


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

void loop() {
  for(int i = 500; i == 1000; i++ ){
    tone ( buzzer, i );
    delay ( 25 );
  }
}

I'd like to make the buzzer to go into a different frequency. Like from 500 Hz to 1000 Hz in a smooth sound (or maybe a little bit of delay). Can you use "for" loop to do that or there is another better function that can help me with this project? Thank You. :slight_smile:

Stuff I use:

  • Arduino UNO
  • Passive Buzzer
  • Windows 10

i == 1000

Change to

i <= 1000

 for(int i = 500; i == 1000; i++ )

Translates to

int i = 500;
while (i == 1000)
{
  //do stuff
  i++;
}

Do you see why the suggested change is needed ?

So... what you mean that you need to make the statement "true" for the loop to loop?

You had:
for(int i = 500; i == 1000; i++ )

Since i is 500 at the start then i==1000 cannot be true, can it?

If you had:
for(int i = 500; i <= 1000; i++ )
Since i is 500 at the start then i <= 1000 would be true as 500 is <= 1000

Does that make sense?

Okay... I get it now. Thanks! :slight_smile: