Skip to content

Instantly share code, notes, and snippets.

@41y08h
Last active March 8, 2022 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 41y08h/cdde547509dc01c2560a58ed4a642f41 to your computer and use it in GitHub Desktop.
Save 41y08h/cdde547509dc01c2560a58ed4a642f41 to your computer and use it in GitHub Desktop.
#include <AceButton.h>
using namespace ace_button;
const int BUTTON1_PIN = 18;
const int BUTTON2_PIN = 19;
const int BUTTON3_PIN = 5;
ButtonConfig config1;
ButtonConfig config2;
ButtonConfig config3;
AceButton button1(&config1);
AceButton button2(&config2);
AceButton button3(&config3);
void handleEvent1(AceButton*, uint8_t, uint8_t);
void handleEvent2(AceButton*, uint8_t, uint8_t);
void handleEvent3(AceButton*, uint8_t, uint8_t);
void setup() {
Serial.begin(115200);
pinMode(BUTTON1_PIN, INPUT_PULLUP);
pinMode(BUTTON2_PIN, INPUT_PULLUP);
pinMode(BUTTON3_PIN, INPUT_PULLUP);
button1.init(BUTTON1_PIN);
button2.init(BUTTON2_PIN);
button3.init(BUTTON3_PIN);
config1.setEventHandler(handleEvent1);
config2.setEventHandler(handleEvent2);
config3.setEventHandler(handleEvent3);
}
void loop() {
button1.check();
button2.check();
button3.check();
}
void handleEvent1(AceButton* button, uint8_t eventType, uint8_t buttonState) {
if (eventType != AceButton::kEventReleased)
return;
Serial.println("Clicked1");
}
void handleEvent2(AceButton* button, uint8_t eventType, uint8_t buttonState) {
if (eventType != AceButton::kEventReleased)
return;
Serial.println("Clicked2");
}
void handleEvent3(AceButton* button, uint8_t eventType, uint8_t buttonState) {
if (eventType != AceButton::kEventReleased)
return;
Serial.println("Clicked3");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment