Mega 2560 led blink with pot analogwrite or digitalwrite?[solved]

Hi, thanks for your reply. I see what you mean about using map and digitalWrite. I used your code and it worked. The weird thing is the led is very faint and I'm not sure why... If anyone has an idea about that I'm all ears lol. It does work perfectly though thanks again!

const int time_total = 2000;      // milliseconds for one PWM phase
  int time_on = 0;
  int pot = A0;
  int led = 13;
  int potVal = 0;

void setup(){
}
void loop() {
   
 
  potVal = analogRead(pot);
  // map the analog input range 0...1023 to a delay range 0 ... 2000 ms
  time_on = map (potVal, 0, 1023, 0, time_total);

  digitalWrite( led, HIGH);
  delay(time_on);

  digitalWrite( led, LOW);
  // wait remaining time for the total time of one PWM phase
  delay(time_total - time_on);
}