Changing the frquency of an LED, a noob looking for help :P

Hello, it´s my first time here, im a college student, i have to learn how to use arduino for one of my classes, i've had like 5 90 minute classes so far.
My teacher assigned my class a couple of programs, the one me and my group got was:
"Change the frequency of an LED, the blinking must be visible."
Generic information that every group got was that the frequency should be between 100 and 700 Hz regardless of the program they got.
He also gave us a generic bit of code that was meant to be used by every group, again, regardless of the program:

float result;
float auxiliary;
void setup() {
 Serial.begin(9600();
}
void loop() {
result=0;
for (int i=0; i< 1000; i++) {
auxiliary= analogRead(A0) - 512;
result= result + pow(auxiliary,2);
delayMicroseconds (1000);
}
result = result/1000 ;
result = pow(result/0,5);
Serial.println (result);
}

I know that i need to somehow use duty to do this, i'm just not sure how, here's the example i got from a previous class:

void setup() {
pinMode(9,OUTPUT);
pinMode(13, INPUT);
}
void loop() {
for (int duty0_128; duty0_128<129; duty0_128 ++) {
  analogWrite (9, duty0_128);
  delay(5000/128);
}
}

I've been looking at guides online but im not really getting anywhere, and also i know that messing with this stuff could potentially brake an LED, so i´m afraid to do something wrong.
The teacher didnt specify it but i´m pretty sure we can just use the LED on pin 13, if not, well that's the easiest part of the program so, it should be easy to change ( unless there´s a diffrent interaction between duty and LED 13 or external LED's ? dunno ).

Anyway, could really use some help from somoene to figure this out.
Thanks for your attention and help in advance :smiley:

An LED blinking at 700 Hz would appear constantly on but dim, the brightness related to duty cycle, probably the same at 100 Hz, most people can't perceive blinking over 50 to 60 Hz, thats why the mains frequency is 50 - 60 Hz, so you can't see the light bulbs blinking.

Basic physics - you can't easily change the frequency of an LED, except perhaps, by cooling it.

outsider:
An LED blinking at 700 Hz would appear constantly on but dim, the brightness related to duty cycle, probably the same at 100 Hz, most people can't perceive blinking over 50 to 60 Hz, thats why the mains frequency is 50 - 60 Hz, so you can't see the light bulbs blinking.

AWOL:
Basic physics - you can't easily change the frequency of an LED, except perhaps, by cooling it.

Thanks for the tips you guys, any idea about what the teacher meant then?
But my trouble goes deeper than just that, i don´t really understand what the duty cycle does perhaps if i make the cycle small enough, the LED would Blink?
I also don ´t really understand what that bit of code that the teacher gave us is supposed to do, he just sort of wrote it on the board and told us " you guys should copy this you"re going to need it".

Here's a little duty cycle sketch to play with, type a number from 0 to 100 in the top of Serial monitor and press [ENTER]. Default cycle Time is 15000 (15 seconds) but you can change it, try 5000 to speed up.
Can't speak for your instructor.

unsigned long cycleStart, onTime, cycleTime = 15000;
bool power = false, oldPower = false;
const byte powerPin = LED_BUILTIN;
byte percent;

void setup()
{
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  if(millis() - cycleStart < onTime)
    power = true;
  else
    power = false;
  if(millis() - cycleStart > cycleTime)
    cycleStart += cycleTime;
    
  if(power != oldPower)
  {  
    Serial.print("Power ");
    Serial.println(power ? "ON" : "OFF");
    oldPower = power;
    digitalWrite(LED_BUILTIN,power);
  }   
  // if there's any serial available, read it:
  if (Serial.available() > 0)
  {
    // look for the next valid integer in the incoming serial stream:
    percent = Serial.parseInt();
    // look for the newline. That's the end of your
    // sentence:
    if (Serial.read() == '\n') {
    }
    percent = constrain(percent, 0, 100);
    onTime = cycleTime * 0.01 * percent;
    cycleStart = millis();
    Serial.println(percent);
  }
}

outsider:
Here's a little duty cycle sketch to play with, type a number from 0 to 100 in the top of Serial monitor and press [ENTER]. Default cycle Time is 15000 (15 seconds) but you can change it, try 5000 to speed up.
Can't speak for your instructor.

unsigned long cycleStart, onTime, cycleTime = 15000;

bool power = false, oldPower = false;
const byte powerPin = LED_BUILTIN;
byte percent;

void setup()
{
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  if(millis() - cycleStart < onTime)
    power = true;
  else
    power = false;
  if(millis() - cycleStart > cycleTime)
    cycleStart += cycleTime;
   
  if(power != oldPower)
  { 
    Serial.print("Power ");
    Serial.println(power ? "ON" : "OFF");
    oldPower = power;
    digitalWrite(LED_BUILTIN,power);
  } 
  // if there's any serial available, read it:
  if (Serial.available() > 0)
  {
    // look for the next valid integer in the incoming serial stream:
    percent = Serial.parseInt();
    // look for the newline. That's the end of your
    // sentence:
    if (Serial.read() == '\n') {
    }
    percent = constrain(percent, 0, 100);
    onTime = cycleTime * 0.01 * percent;
    cycleStart = millis();
    Serial.println(percent);
  }
}

thanks, it has a lot of things that i havent learned yet, but im going to see what i can learn from it, but if anyone else wants to give any more tips they are wecome to do it :slight_smile:

Should have told you, Duty Cycle is the percentage of ON time compared to total cycle time, example; cycle time is 10, ON time is 1, duty cycle is 10% (1 /10) off time is cycle time - duty cycle (9 or 90%).