7. Using the Pololu AVR Library for your own projects

After getting one of the simple examples to work with an Orangutan controller, you can start working on more complicated programs of your own. The library provides easy access to all of the features of the Orangutans, including the LCD screen, buttons, LEDs, motors, and buzzer. There are also functions in the library that make it easy for you to do more general-purpose operations with the AVR, such as timing and analog-to-digital conversion. The library also provides support for the Pololu QTR sensors, which should work even if you are not using an Orangutan controller. For a complete list of functions provided by the library, see the command reference.

Usually, the easiest way to adapt this code to your own projects will be to start with a working example and gradually add the things that you need, one step at a time. However, if you want to start from scratch, there are just a few things that you need to know. First, to use the library with C, you must place one of the following lines

#include <pololu/orangutan.h>
#include <pololu/3pi.h>
#include <pololu/qtr.h>

at the top of any C file that uses functions provided by the library. To use the library with C++, the equivalent lines are

#include <pololu/orangutan>
#include <pololu/Pololu3pi.h>
#include <pololu/PololuQTRSensors.h>

The line or lines that you include depend on which product you are using with the library.

Second, when compiling, you must link your object files with libpololu.a. This is accomplished by passing the -lpololu option to avr-gcc during the linking step.

To add the -lpololu option within AVR studio, select Project > Configuration Options > Libraries. You should see libpololu.a listed as an option on the left column. Select this file and click “add library” to add it to your project.

Finally, we also strongly recommend the linker option -Wl,-gc-sections. This causes unused library functions to not be included, resulting in a much smaller code size. To include this in AVR Studio, select Project > Configuration Options > Custom Options. Click on [Linker options] add add -Wl,-gc-sections to the list. This linker option is included in both the AVR Studio and Linux-based example programs described earlier.