Using the GPIO class

I’m new to Daisy, and attempting to use the GPIO class. I’m trying to compile the code from the LibDaisy docs:

#include "daisy_seed.h"
using namespace daisy;
using namespace daisy::seed;
DaisySeed hw;
int main(void) {
  // Initialize the Daisy Seed
  // Create our GPIO object
  GPIO my_button;
  GPIO my_led;
  // Initialize the GPIO object for our button */
  my_button.Init(D0, GPIO::Mode::INPUT, GPIO::Pull::PULLUP);
  // Initialize the GPIO object for our LED
  my_led.Init(D1, GPIO::Mode::OUTPUT);
  while(1) {
    // And let's store the state of the button in a variable called "button_state"
    bool button_state = my_button.Read();
    // And we want to light up the LED while we're pressing the button 
    // so let's use the "!" to flip over the button_state

I created a project using

python3 create gpio_test --board seed

and added this code. But I get the following errors:

gpio_test.cpp:4:24: error: ‘seed’ is not a namespace-name
4 | using namespace daisy::seed;
| ^~~~
gpio_test.cpp: In function ‘int main()’:
gpio_test.cpp:13:3: error: ‘GPIO’ was not declared in this scope; did you mean ‘GPIOA’?

Have I failed to install the toolchain correctly? I am able to build and run the other seed examples without issue.

Ok, so it seems I just needed to update libDaisy (the version I had was missing the namespace seed entirely), I’m assuming this was updated regularly? Will leave this message here in case anyone else has this issue (or happy for a moderator to delete).

1 Like

Thanks for providing the info above for others. The GPIO code as it is, is fairly new (especially at the time of your post).

1 Like