Problems with GPIO and Touch Button

Hey, i have an issue with the Daisy Seed and and a touch button connected to a GPIO Pin.

I loaded the the example code for the button and changed it so it doesnt light the LED but prints 1 when pressed in the serial monitor.

If the button is pressed it stays at 1 for roughly 10 seconds and then goes off. Same when the button should light the LED.

Is there something i need to code, or is that a hardware limitation?

I encountered the issue when trying to implement an ADSR Envelope and the Sustain Phase only lasts for the 10 seconds mentioned above.

Thanks in advance!

Edit: I work with Visual Studio Code, i dont know if that is relevant.

In general, when posting a question like this, it is very important to post an actual piece of code which demonstrates the problem. You’re probably doing something wrong.

Hey, thanks for the reply. Here is the code i use:

#include “daisy_seed.h”

using namespace daisy;
using namespace daisy::seed;

DaisySeed hw;

int main(void) {
// Initialize the Daisy Seed

// Start logging for printing over serial


// Create our GPIO object
GPIO my_button;

// Initialize the GPIO object for our button */
my_button.Init(D0, GPIO::Mode::INPUT, GPIO::Pull::PULLUP);

while(1) {
// And let’s store the state of the button in a variable called “button_state”
bool button_state = my_button.Read();
hw.PrintLine(“ADC Value: %d”, button_state);


I didn’t set up hardware to test this, but I have several comments:

  • add a System::Delay(100) line inside the ‘while’ loop. You’re trying to send thousands of log messages per second. It doesn’t have to be 100, just some number that limits the rate of the loop. A value of 100 will loop 10 times per second.
  • you’ll need to debounce the button. Try using the libDaisy Switch class instead of raw GPIO.

EDIT: I ran this, and with a Delay() in the loop, it works as expected.

1 Like