A Library Question

I am trying to understand more about how Arduino Libraries work.
To be to be more specific. Knowing what code functions / commands are available when using a library.

I have been messing about with a rotary encoder trying to control a Stepper motor connected to an old radio dial cord and some of the code requires the stepper library.

So am I correct in thinking that in the Stepper library the only functions the coder can use when accessing that library are

Stepper
Stepper
setSpeed
Step

Thanks ( Always learning !)

For any library, the definitive reference for all available functions (and how they are called) is the source code itself (.cpp and .h files)

Actually the only functions are setSpeed and step. Stepper(steps,pin1,pin2) and Stepper(steps,pin1,pins,pin3,pin4) are constructors. Constructors are used to create new objects of the class.

So when using a library and writing code how do you know what can be used specific to say the stepper library ?

As I said, the definitive is to slog your way through the library's source code. You can learn some good programming techniques doing that -- and some bad ones.

If you're lucky the library's examples will provide enough guidance.

As you have mentioned the Stepper library have a look at the AccelStepper documentation as an example of how it should be done (but rarely is).

...R

Read the documentation:

Pros: Easier to read.
Cons: May be incomplete or incorrect.

OR

Read the source code:

  • File > Examples > Stepper > select any example
  • Sketch > Show sketch folder
  • Navigate up two folder levels, then down to the src folder, if present. Open the source files with a text editor.

pert:
Read the documentation:
Stepper - Arduino Reference
Pros: Easier to read.
Cons: May be incomplete or incorrect.

What annoys me about Arduino’s library documentation is that it rarely shows prototype-fashion declarations for the functions.

If it did, I could tell in just one glance what types of arguments (parameters?) it takes and what type it returns. There should be one such declaration documented for each flavor in the case of overloaded functions.

I actually think that the prototype style notation is confusing to beginners. I do think it's essential to always document the return type of the function and the type of each parameter. The Arduino documentation attempts to do this in a more beginner-friendly, if less concise, fashion but I think the specific format could be tweaked a little and used consistently throughout the reference pages. It's currently somewhat patchy. They are getting ready to release a complete rework of the language reference pages in a few days but I'm not sure how much improvement there will be in content and in fact there will be some regressions. However, the great thing is this will allow anyone to propose improvements by simply submitting a pull request to the reference repository.

You can try this switch pack. It can read encoders. It has a tutorial and 3 examples on how to use encoders.

Jacques

Thanks for all the replies and suggestions to try