C++ API#
Detailed Description#
The C++ API reference documentation for libpisoundmicro.
Quick Start#
First, install the development package:
sudo apt install libpisoundmicro-dev
Then, let's create a simple program to read the GPIO value of pin B03:
#include <pisound-micro.h>
#include <iostream>
int main(int argc, char **argv)
{
// Initialize the libpisoundmicro library. The libInit destructor will automatically
// deinitialize it.
upisnd::LibInitializer libInit;
if (libInit.getResult() != 0)
{
std::cerr << "Failed to initialize libpisoundmicro: "
<< libInit.getResult() << std::endl;
return 1;
}
// Setup a gpio input Element with B03 pin and pull-up enabled.
upisnd::Gpio gpio = upisnd::Gpio::setupInput(
upisnd::ElementName::randomized(),
UPISND_PIN_B03,
UPISND_PIN_PULL_UP
);
if (!gpio.isValid())
{
std::cerr << "Failed to setup GPIO." << std::endl;
return 1;
}
// Read the value.
if (gpio.get())
std::cout << "B03 is high." << std::endl;
else
std::cout << "B03 is low." << std::endl;
// The pisound-micro resources will get automatically relased upon
// destruction of the gpio and libInit objects.
return 0;
}
example.cpp
and compile it:
g++ example.cpp -lpisoundmicro -o example
And run it:
./example
You should see it output either "B03 is high." or "B03 is low.", depending on the B03 pin state.
See the below documentation for more details.
Classes#
Type | Name |
---|---|
class | upisnd::Activity Activity element class. |
class | upisnd::AnalogInput Analog input element class. |
class | upisnd::Element An Element class for shared functionality of all Pisound Micro Elements. |
class | upisnd::Encoder |
class | upisnd::Gpio |
class | upisnd::LibInitializer Simply calls upisnd_init andupisnd_uninit in its constructor and destructor, for convenience. |
class | upisnd::ElementName A helper class for formatting Element names. |