Mega 2650 and pull-down resistor questions

I have a 2560 with a PB between 5v and a pin 40.
The PB when pressed should turn a LED on. When PB is not pressed and place my finger close to the wire connected to pin 40 the led begins to flicker indicating I need a pull-down resistor.

Add a 10K resistor everything works as perfectly.

The documentation is a bit confusing. Is there a command I need to use to invoke the pull-down resistor? I'm finding pinMode() as INPUT_PULLUP but is there a pull-down command?

Is there an internal pull-up/pull-down resistor under software control? If so, what's the command?

Or do I just use an external 10K res for all PB inputs?

Thanks

There's no internal pulldown.

So use INPUT_PULLUP to turn the internal pullup on, and change the logic to be active low, ie button pressed is low, button released is high, with the button from pin to ground.

I could, but the LED might be dimly lit.

I guess what you are saying is one has to use external pull-down resistors.

Doug101:
I could, but the LED might be dimly lit.

Why would that be?

Doug101:
I guess what you are saying is one has to use external pull-down resistors.

Wrong guess ;). I'm saying use the internal pullups and sort the logic in code.

Do you know why pull-up and pull-downs are needed?

A pullup will allow enough current to flow to dimly light a LED.

Doug101:
Do you know why pull-up and pull-downs are needed?

Yes, to ensure an input is steered high or low respectively when its switch isn't taking it the other way.

So your input where your button is, with a pullup, is normally high, goes low when pressed. You logic says, if the input pin is low (ie pressed), turn the led on some output pin on, else (ie button unpressed, high) turn led off.

The led's on an output pin, so the pullup or pulldown on the button's input pin has nothing to do with the led's brightness.