Why don't I have to set a digital pin to OUTPUT when using the tone function?

Hi, just started using the Arduino, and I'm going through the Arduino Projects Book.

I was just wondering why I don't need to set the digital pin to OUTPUT when using the tone function when digital pins are INPUT by default.

I also tried setting the Digital Pin I used the tone function on explicitly to INPUT, and the project still worked, I mean the tone function still worked.

Same question applies to using Servo.attach..

When do I absolutely need to set it to OUTPUT and when does it automatically assume output?

Thank you to anyone for their time in answering this.

The Tone and Servo libraries do it for you. If they didn't people would complain that they used the library and it "doesn't work".

If you aren't using a library, then you would need to set the pin to output yourself, if that is what you want.

To be "absolutely" certain, for a particular library, you would need to look at the library code.

Thank you very much. That cleared things up. Is there a way to see what is from the library and what is primitive to the language?

  1. Learn the language.
    or
  2. Read the source code of the library, it is available.