Getting the button state on a Patch SM

Getting the button state on a Patch SM

I have a ready made Patch Init module (this one: patch.Init() - Daisy) and I’m trying to get the state of the push button in my code and then light up the test LED on the board..

As I see it the full code should be

#include "daisy_patch_sm.h"
#include "daisysp.h"

using namespace daisy;
using namespace patch_sm;
using namespace daisysp;

DaisyPatchSM hw;

int main(void)
{
	hw.Init();

	Switch         button;
  	button.Init(DaisyPatchSM::B7, hw.AudioCallbackRate());

	while(1) {
		bool button_state = button.Pressed();
        hw.SetLed(button_state);
	}
}

but the state is always false. What am I doing wrong?
I ran the Blink example code just fine, so my toolchain setup and hardware seems to be working properly.

Thanks in advance,
Sebastian

I suggest you look at :DaisyExamples/patch_sm/HardwareTest for an example of how to read the button.

You need to call the Debounce method for the button, at the rate provided in the Init method.

In my experience, many questions can be answered by studying the examples.

Thank you very much! I looked at that example but as I didn’t process any audio I just ignored the audio callback function. It works fine now, cool!