I think this may appear simplistic, but in my quest to learn Arduino and its code I look at others' code and try to figure out what's going on. Using the Arduino.cc reference allows me to see how the standard commands work, but I get a bit stuck when libraries are involved.
An example is below, from a debounce (.h) library...
#include <Bounce2.h> #include "Arduino.h" #include "ButtonToggleLibrary.h" Bounce debouncer = Bounce(); Button::Button(byte BUTTON_PIN) { #define LED_PIN 13
** debouncer.attach(BUTTON_PIN, INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode**
** debouncer.interval(25); // Use a debounce interval of 25 milliseconds** } void Button::buttonToggle() {
** int ledState = LOW;**
** debouncer.update(); // Update the Bounce instance**
** if ( debouncer.fell() ) { // Call code if button transitions from HIGH to LOW**
** ledState = !ledState; // Toggle LED state**
** digitalWrite(LED_PIN, ledState); // Apply new LED state**
** }** }
There are statements such as 'debouncer.update', 'debouncer.fell' and the like, to which I can find no explanation.
Are there explanations, and where/how do I find them?
Usually libraries have websites and/or readme files that explain what functions are available through the library and how to call them. Usually a quick google of the library name will help you find what you need.
If all else fails, look at the library .h file for a list of functions, figure out by the function name what you are interested in, and then look at the .cpp for implementation of those functions you're interested in.
Glorymill:
Are there explanations, and where/how do I find them?
Many times the best (and only) documentation for libraries is the source code itself. Generally speaking, a library will consist of a .h file (containing the “interface” that your application code needs to use the library) and a .cpp file (containing the implementation of library’s functions). Also, generally speaking, libraries are written to use C++ classes and Object Oriented Programming techniques.
So, depending on your proficiency with C++ and OOP, you’ll first need to become familiar with those topics and then study the source code. It's also helpful to study the examples that come with the library.
Google is my friend, read the readme, look at the .h file, and study classes in c++. The classes part is the one I have tried to get my head around before...it seems to make sense until I try to use a class within my own code (or if I have a week away from code-study).