Do we need pinMode() function?


#1

What’s this PinMode, and why do I need to set it?
Isn’t it automatic that when I digitalRead I am in input mode, and when I digitalWrite I am in output mode?
Because in the Go example, there’s a function to set the PinMode, but my grovepi just works, doesn’t matter if I set the pin mode or not.


#2

Hi @LuCavallin,

I don’t think you need to worry on the pinMode() function.


As far as I remember, the pinMode() isn’t necessary.
The code is going to work well without it.
But at the same time, it doesn’t hurt to use it.


Here’s an analogy.

You can think of the pinMode() function as the @Override annotation in Java.
The annotation is not necessary, it just tells the compiler the following function is going to be overridden - so it’s helping the compiler know that there must be an overridden function, otherwise it throws an error.

Obviously, I’m talking about different functionalities here, but what it’s important is the analogy.


Hope I’ve made myself clear.

Thank you!