The Terrarium platform was designed to work as seamlessly as possible with the libDaisy Petal API, but because the number of toggle switches (and footswitches) deviates from the Petal interface we need to use a different set of constants to address them.
The Terrarium header file (terrarium.h) can be downloaded from this link.
At the top of our source file we need to include the Terrarium header file and direct the compiler to use the "terrarium" namespace.
Now we can access the state of the footswitches and toggle switches using the standard Daisy functions by specifying the Terrarium switch constants.
Here is the code in an example project. In this example the footswitches toggle the Terrarium LEDs on and off.
The Terrarium header file (terrarium.h) can be downloaded from this link.
At the top of our source file we need to include the Terrarium header file and direct the compiler to use the "terrarium" namespace.
C++:
#include "terrarium.h"
using namespace terrarium;
Now we can access the state of the footswitches and toggle switches using the standard Daisy functions by specifying the Terrarium switch constants.
C++:
if (hw.switches[Terrarium::FOOTSWITCH_1].Pressed())
{
// Footswitch 1 is pressed
}
C++:
if (hw.switches[Terrarium::SWITCH_1].Pressed())
{
// Toggle switch 1 is ON
}
Here is the code in an example project. In this example the footswitches toggle the Terrarium LEDs on and off.
C++:
// PedalPCB Terrarium Switch Example
#include "daisy_petal.h"
#include "daisysp.h"
#include "terrarium.h"
using namespace daisy;
using namespace daisysp;
using namespace terrarium;
DaisyPetal hw;
dsy_gpio led1;
dsy_gpio led2;
void AudioCallback(float *in, float *out, size_t size)
{
hw.DebounceControls();
hw.UpdateAnalogControls();
if (hw.switches[Terrarium::FOOTSWITCH_1].RisingEdge())
dsy_gpio_toggle(&led1);
if (hw.switches[Terrarium::FOOTSWITCH_2].RisingEdge())
dsy_gpio_toggle(&led2);
}
int main(void)
{
hw.Init();
hw.StartAdc();
hw.StartAudio(AudioCallback);
led1.pin = hw.seed.GetPin(22);
led1.mode = DSY_GPIO_MODE_OUTPUT_PP;
led1.pull = DSY_GPIO_NOPULL;
dsy_gpio_init(&led1);
led2.pin = hw.seed.GetPin(23);
led2.mode = DSY_GPIO_MODE_OUTPUT_PP;
led2.pull = DSY_GPIO_NOPULL;
dsy_gpio_init(&led2);
for(;;)
{
}
}
Last edited by a moderator: