can't turn LED off on pin 13

I’m writing up a basic program to read a random analogue value and use it as seed for a delay factor before turning an LED on, I thought I’d use the built in LED on pin 13 but I won’t go out even if I comment out the code turning it on and it is turned off manually in there setup part of the code.

unsigned int seed, D;


void setup() {

  digitalWrite(13, LOW);
}

void loop() {

  seed = analogRead(0);
  D = seed * 100;
  if ((D > 5000) && (D < 60000)){
    delay(D);
   // digitalWrite(13, HIGH);
  }
}

I see that once the led is turned on, never turns off, you don't have a digitalWrite (13, LOW) in any point of the loop() function, so it never turns off. It turns on once after the delay() and keeps on ever and ever.

Your code turns the LED off for me at startup. But setup() was changed to this so when the LED came on it would glow full brightness.

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

oh i see the pin still needs setting as an output

sparkylabs: oh i see the pin still needs setting as an output

Yes, I did'nt realize!!