The Terrarium platform was designed to work as seamlessly as possible with the libDaisy Petal API. One area where the Terrarium deviates from the standard Daisy Petal API is the method of controlling the two indicator LEDs.
This post will describe how to control the state of the two indicator LEDs of the Terrarium.
First we have to create an instance of dsy_gpio for each LED that we plan to control. In this case we will name our instance led1.
Next we configure the parameters for the instance we created. The left LED is on Pin 22 of the Daisy Seed, the right LED is on Pin 23 of the Daisy seed.
Now we can control the LED.
Here is the complete code in an example project. In this example the two LEDs will alternate back and forth every 1000ms.
This post will describe how to control the state of the two indicator LEDs of the Terrarium.
First we have to create an instance of dsy_gpio for each LED that we plan to control. In this case we will name our instance led1.
C++:
dsy_gpio led1;
Next we configure the parameters for the instance we created. The left LED is on Pin 22 of the Daisy Seed, the right LED is on Pin 23 of the Daisy seed.
C++:
led1.pin = hw.seed.GetPin(22); // This instructs our instance to interact with Pin 22 (Left LED) of the Daisy Seed.
led1.mode = DSY_GPIO_MODE_OUTPUT_PP; // This configures the pin for Push-Pull operation
led1.pull = DSY_GPIO_NOPULL; // This disables the internal pull-up resistor for the pin
dsy_gpio_init(&led1);
Now we can control the LED.
C++:
dsy_gpio_write(&led1, true); // Turn LED on
dsy_gpio_write(&led1, false); // Turn LED off
dsy_gpio_toggle(&led1); // Toggle the state of the LED
Here is the complete code in an example project. In this example the two LEDs will alternate back and forth every 1000ms.
C++:
// Terrarium LED example
#include "daisy_petal.h"
#include "daisysp.h"
using namespace daisy;
using namespace daisysp;
DaisyPetal hw;
dsy_gpio led1;
dsy_gpio led2;
int main(void)
{
hw.Init();
led1.pin = hw.seed.GetPin(22);
led1.mode = DSY_GPIO_MODE_OUTPUT_PP;
led1.pull = DSY_GPIO_NOPULL;
led2.pin = hw.seed.GetPin(23);
led2.mode = DSY_GPIO_MODE_OUTPUT_PP;
led2.pull = DSY_GPIO_NOPULL;
dsy_gpio_init(&led1);
dsy_gpio_init(&led2);
dsy_gpio_write(&led1, true);
for(;;)
{
dsy_gpio_toggle(&led1);
dsy_gpio_toggle(&led2);
dsy_system_delay(1000);
}
}
Last edited by a moderator: