Set pin as output, then set low

This year I joined a new firm and took over an Arduino project. Throughout the code, where a pin is to be used as an output, I see:

    digitalMode( PIN_X, OUTPUT );
    digitalWrite( PIN_X, 0u );

Is this how you're supposed to do it?

When you first set the pin to an output, does it start off as high, or does it start off as low?
If it starts off as high, then when you have code such as the above, will the pin be high for a few microseconds before going low?

I'm kind of new to Arduino too, but I believe you'd want to do digitalWrite( PIN_X, LOW );. I think the pin floats before you set it, so it may not be high or low.

But in most circumstances, you set the pin mode once, in setup(), then just do digital writes whenever you need to.
C

Does anyone know for sure whether the pin is high or low after "digitalMode(PIN_X, OUTPUT)" ?

Not offhand, but have you just tried it? Just sayin'

What board and library are you using? digitalMode() doesn't compile, but pinMode() does.
C

yeah I meant pinMode

1 Like

So, what did the pin do when you tried it? High? Low?

You could also try digitalWrite before doing pinmode, maybe you can preset what the pin will do when turned into an output?
I don't know, by the way, I'm not needling. I'm curious.
C

This seems to answer all your questions.

2 Likes

@asyork
Thanks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.