Problems with autoreset on Leonardo

TimMJN:
the code isn't running

You have this line in setup():

  while (!Serial) {};

That will cause your program to wait at that point until the Serial Monitor is opened. I doesn't appear that you are even using Serial at all in your program so you could probably just comment or remove the lines:

  Serial.begin(9600);
  while (!Serial) {};