Arduino Nano strange behavior

You set 6 as input, but then write to it?

Doing that activates the built in pullup resistor. Equivalent to the more explicit

pinMode(6, INPUT_PULLUP);

Incidentally, it seems a shame not to give all of the pins meaningful names

This is confusing too

  // set the brightness of pin 9:
  test = digitalRead(6);

Comments should at the very least match the code.