Two button both pressed (sample LongPress)
ysoyipek opened this issue · comments
Yusuf Soyipek commented
Hi, congratulations on a very nice project.
What I want to ask is, is it possible to have a feature that I think would be very nice if added?
I need to use the long-press method of two keys to turn a device off and on safely.
I am able to check and catch the isPressedRaw() property on both keys in the kEventLongPressed event. But the event throwing occurs on the second depressed key.
I wonder if it's possible to do two-key presses with the existing library?
code;
#include <AceButton.h>
using namespace ace_button;
#define PIN_BUTTON1 6
#define PIN_BUTTON2 7
AceButton button1(PIN_BUTTON1);
AceButton button2(PIN_BUTTON2);
void handleEvent(AceButton *, uint8_t, uint8_t);
void setup()
{
pinMode(PIN_BUTTON1, INPUT_PULLUP);
pinMode(PIN_BUTTON2, INPUT_PULLUP);
ButtonConfig *buttonConfig = ButtonConfig::getSystemButtonConfig();
buttonConfig->setEventHandler(handleEvent);
buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
buttonConfig->setLongPressDelay(3000);
}
void handleEvent(AceButton *button, uint8_t eventType, uint8_t buttonState)
{
switch (eventType)
{
case AceButton::kEventLongPressed:
if (button1.isPressedRaw() && button2.isPressedRaw())
{
Serial.println("LongPressed: Both");
}
break;
}
}
terminal;
LongPressed: Both
LongPressed: Both