Very quick question regarding pins set as OUTPUT.

Basically, when you set a pin as Output, is there a default voltage if not specified by digitalWrite ?

The default is LOW.

There is no default - it's whatever it was set to before the pinMode call.

At power-up that will be low. If it has been changed previously before the pinMode call it will be whatever it was changed to.

If it was an input and the pull-up resistor was enabled (INPUT_PULLUP) then you may find it's high. It's hard to tell from the data sheet - you enable the pull-up by writing 1 to the relevant PORT bit - if you then switch to output I guess that stays as 1 and the output defaults to HIGH.

If PORTxn is written logic one when the pin is configured as an input pin, the pull-up resistor is activated. To switch the pull-up resistor off, PORTxn has to be written logic zero or the pin has to be configured as an output pin. The port pins are tri-stated when reset condition becomes active, even if no clocks are running. If PORTxn is written logic one when the pin is configured as an output pin, the port pin is driven high (one). If PORTxn is written logic zero when the pin is configured as an output pin, the port pin is driven low (zero).

Does the same apply to inputs? For example what would happen if we set the portb register to 11111111 and then set the ddrb rgister to 0? would the internal pullups be enabled?

Vinter: Does the same apply to inputs? For example what would happen if we set the portb register to 11111111 and then set the ddrb rgister to 0? would the internal pullups be enabled?

Yes.

Vinter: Does the same apply to inputs? For example what would happen if we set the portb register to 11111111 and then set the ddrb rgister to 0? would the internal pullups be enabled?

Yes. If you manipulate the registers directly, that is the behavior you would see.

However, if you use the Arduino function pinMode() and set it to mode "INPUT", this will disable the internal pull-up. "INPUT_PULLUP" will enable the internal pull-up. (This behavior changed when INPUT_PULLUP was introduced , which 1.0.1 or after.)