Adjustable frequency

I have a simple code and I would like to know how I could adjust the frequency using a potentiometer

int ledPin = 13; // LED connected to digital pin 13

void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}

void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delayMicro(1); // waits for a second
}

  delay(1);                  // waits for a second

No, it doesn't

delayMicro(1);    You clearly didn't even try to compile that code.

Ok is suppose to be delayMicro(1) and thats about 143khz

Nope.

I compiled this and it worked just fine, take a look and confirm if its ok.

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

void loop()
{
digitalWrite(13, HIGH);
delayMicroseconds(100); // Approximately 10% duty cycle @ 1KHz
digitalWrite(13, LOW);
delayMicroseconds(1000 - 100);
}

Yes, that's OK, apart from the magic numbers and the delay()s, and the lack of code tags.

Ok then not sure of the magic numbers but IF I needed to adjust the frequency I would think I need to change the delay in Microseconds.

That's right.
Bear in mind an ordinary analogRead will take around 100 microseconds.

the delay the analogRead takes to read wont be a problem. How would I implement that function in the code?

enzyb:
the delay the analogRead takes to read wont be a problem.

Are you sure?

Ok let me get this straight, by delay do you mean when the pot is turned to adjust the frequency it will be delayed before its adjusted by 100 microseconds?

The loop() function will be slowed by roughly 100 microseconds each time you call analogRead.
That will affect your maximum output frequency

So after its slowed wont it then readjust to the correct output frequency?

Do you mean "can I adjust the output frequency?".
If so, then the answer is yes.

ok for example having both delays at 100 microseconds will give 1khz and reducing both delays with a pot to 90 microseconds would reduce the frequency to 990khz but because of the analogRead feature it would take 100 microseconds to reduce to 990khz. thats my understanding of what you said.

if thats the case then I have no problem with that.

if thats the case then I have no problem with that.

I (and I suspect you) have a problem with your arithmetic, and your concept of the word "reduce"

(And your spelling of "kHz")

how would I modify the code to change the frequency?

What have you tried?
How did it go for you?

are you not understanding what I am saying.

I gave a code ill send that code again.

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

void loop()
{
digitalWrite(13, HIGH);
delayMicroseconds(100); // Approximately 10% duty cycle @ 1KHz
digitalWrite(13, LOW);
delayMicroseconds(1000 - 100);
}

the frequency output of this code is 1 kilohertz I would like to modify this code so that I can use a Potentiometer to adjust the frequency from 0hertz to 1 kilohertz.

hopefully those words are good enough to understand.

The words are good enough to understand, though again, the code tags are missing.

What do you understand by "frequency"?
How does that relate to the use of "delayMicroseconds"?

When you answer those questions, you're a long way to a solution.

What code have you tried?
How did that code fail to come up to your expectations?

I'm trying to get you to think, rather than giving you a solution.

(You have five minutes between posts - why not try using those minutes productively by experimenting?)