Leonardo will Appear and Disappear in Device Manager

Hello all, this is a strange first post and I hope someone may be able to offer some insight. I recently received my Leonardo and I am completely new to embedded systems and microcontroller use/programming. On to the issue!

My Leonardo was functional for two days, no issues. Then one day I plugged into the USB port I always used (COM3) and uploaded a sketch. I received an error stating that COM3 was already in use. I then opened my Device Manager and noticed that the 'Ports' option was not there despite that the Leo was plugged in. I unplugged it and plugged it back in and the it showed briefly on COM4, the disappeared altogether again. I have another Leo which I tried and it worked perfect!

I'm wondering, could my sketch have stuck my board? I've seen mention of a DFU to hard reset the board but can't find Leo specific instructions. In the event it helps my OS is Windows 7 Home. Any insight or thoughts are most welcome! Thank you!

I think that's a normal behavior with that board. I don't have one anyway to confirm.

dmielken: I plugged into the USB port I always used (COM3) and uploaded a sketch.

What sketch?

If the sketch changed it to behaving like a mouse or keyboard, it will stop looking like a COM port.

I believe the Leonardo page describes how to work around that, something to do with holding down reset and letting go at the moment the sketch starts uploading.

//To have an LED come on when initialized and flash when an input comes on//

int led = 13;
int analogIn = A3;
int val = 0;

void setup() 

{
  pinMode(led, OUTPUT);
  pinMode(analogIn, INPUT);
}

void loop()

{
  digitalWrite(led, HIGH);
  
  val = analogRead(analogIn);
  
  loop();
{  
    digitalWrite(led, LOW);
    delay(50);
    digitalWrite(led, HIGH);
    delay(50);
} 
  
  
}

Thanks for the replies so far. This was the code that was uploaded to the unit. I'll have a look at the Leo page again and check it out!

Ok update on this. I managed to get the Blink sketch back on the board before the Serial port disappeared again, so I'm happy that my board isn't bricked :)

That being said I now need to find a way to keep the Serial port from disappearing or becoming greyed out in the Tools menu in the IDE.