Hi everyone,
I’m not sure what I’m doing wrong, but when I connect multiple buttons to digital pins, I keep receiving false triggers from other buttons. I tried various pins, tried GPIO or Switch class uses, and tried using resistors instead of PullUp, but it seems like I’m missing something, and I’m not sure what. Here’s the example connection I am using to connect four 2-pin buttons directly to board (I’m using an 8 pin connector as daisy seed in the breadboard designer):
The buttons are connected to pins D15 to D18 and DGND+AGND.
And the code:
#include "daisy_seed.h"
#include "daisysp.h"
using namespace daisy;
using namespace daisysp;
DaisySeed hw;
daisy::Switch b1, b2, b3, b4;
void buttonListener(daisy::Switch button, int pin) {
if (button.RisingEdge() == 1) {
hw.PrintLine("Pressed %d", pin);
} else if (button.FallingEdge() == 1) {
hw.PrintLine("Released %d", pin);
}
}
int main(void)
{
hw.Init();
hw.StartLog(true);
hw.PrintLine("serial connected");
b1.Init(hw.GetPin(15), 1000, daisy::Switch::TYPE_MOMENTARY, daisy::Switch::POLARITY_NORMAL, daisy::Switch::Pull::PULL_UP);
b2.Init(hw.GetPin(16), 1000);
b3.Init(hw.GetPin(17), 1000);
b4.Init(hw.GetPin(18), 1000);
while(1) {
b1.Debounce();
b2.Debounce();
b3.Debounce();
b4.Debounce();
buttonListener(b1, 15);
buttonListener(b2, 16);
buttonListener(b3, 17);
buttonListener(b4, 18);
}
}