Why must pinMode() be inside the setup() section.
Is this mandatory and where is this described in the reference.
Cant find anything on this in the reference section.
Harry
Why must pinMode() be inside the setup() section.
Is this mandatory and where is this described in the reference.
Cant find anything on this in the reference section.
Harry
No, it isn't mandatory to be in setup, but normally, it is something you do only once for the lifetime of a sketch.
It's not mandatory to have it in setup(), it can be anywhere (in a function). But in 99% of the cases the mode of a pin is fixed in the design. So no need to call it more than once aka it ends up in setup().
It is mandatory to call pinMode() (but where doesn't matter as explained) if you want a pin to have a different mode than INPUT (the default) otherwise the code simply doesn't know what to do with a pin.
septillion:
It's not mandatory to have it in setup(), it can be anywhere.
Can it be placed in the global area?
Yes it can.
It won't compile, but you already knew that.
GolamMostafa:
Can it be placed in the global area?
No. It's executable code. It must go in a function.
TheMemberFormerlyKnownAsAWOL:
Yes it can.
It won't compile, but you already knew that.
Tough question; but, easy answer! (+).
gfvalvo:
No. It's executable code. It must go in a function.
Then the first sentence of Post#2 is not complete?
You are correct, added it