Why does Leonardo change com ports?


This is my first experience with the Arduino Micro with the AtMega32u4.

I have been working with the Mouse and Keyboard library.

Normally When I program a sketch from my PC theUSB port is COM20. When the sketch runs, the USB port changes to COM21. When I re-program the same sketch, the port changes back to COM20, the part is re-programmed, then it changes to port COM21 again while the sketch is running.

But when I have a sketch which calls the Mouse or Keyboard library functions it never returns to port 20 to allow me to re-program it. It just times out with an error. In this case have to connect it to an STK600, erase the program and re-programming the boot loader.

This just can't be normal.

What am I missing concerning the use of the Mouse and Keyboard libraries?

Once the USB port turns into a mouse it can't also be a serial port.

To reprogram you have to hold down the Reset button, and let go when the upload starts.