Default value when creating DO with 'pinMode'

Hello,

So I tried searching for this but, I have yet to find the answer (Still searching...). I figured this would be a decent question to pose.

Okay... When using 'pinMode' as to setup a digital output (example - pinMode(led, OUTPUT)), is it safe to assume that the default setting of the output is 'LOW'?

Meaning, unless otherwise changed to 'HIGH' with 'digitalWrite()', will the output of the pin always stay low?

If this has already been answered and you know the link, feel free to paste it. Intuitively, it seem like question that has been asked several times. Sorry if it has :(

Thank you

Yes. Yes.

If by “Arduino” you mean an Arduino with an AVR processor. I have no idea how the SAM pin driver works.

By default, all pins are INPUT.

If a pin is set as input, and you do digitalWrite(pin,HIGH); that will turn on the pullup (eg, like setting pinMode to INPUT_PULLUP).

If you have a pin that is set as an input (not input_pullup, and you haven't turned the pullups on with digitalWrite() ), and change it to an output, it will output low.

If the pin is set input_pullup, or you've turned on the pullups with digitalWrite, and you set it OUTPUT, it will output high.

Note that when you set a port that was output to INPUT, that will turn off the pullup, even if it was previously outputting high (pinMode sets the PORTx register as well as the DDRx register when setting INPUT or INPUT_PULLUP, but it leaves it alone when setting a port OUTPUT, for good reasons).

I'm not sure about the internal implementation for the other chips (like SAM for the due) either - but if it's different, they probably thought of this when they added support for the chip, and made it act the same if you use digitalWrite(), pinMode() and the other helper functions.

Thank you Coding Badly & DrAzzy

clarification:

In my example, the variable 'led' is a boolean data type. so:

boolean led = 13

void setup(){ pinMode ( led, OUTPUT );

void loop(){ // misc code that does not use variable 'led' }

boolean is an inappropriate datatype for storing a pin number.

boolean can store a value of true or false. If you assign 13 to a boolean, that boolean has the value true. If you later convert that back to a number, it comes out as 1 (false comes out as 0).

Use an int or byte to store the pin number.

:astonished: Whoops! I feel silly :confused:

correction:

int led = 13;

void setup(){ pinMode( led, OUTPUT ); }

void loop(){ //misc code not modifying 'led' }