//#include <Adafruit_SSD1306.h> // v2.5.1
#include <EasyButton.h> // v.2.0.1
//#include <ArduinoSort.h>
//#include <EEPROM.h> // v.2.0.0
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define SCREEN_ADDR 0x3C /// <- 0x3C for 128x32 ; 0x3D for 128x64
//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT);
//...
#define xyz
//...
// Event Types
#define ET_NONE 0
#define ET_BACK 1
#define ET_SELECT 2
#define ET_LEFT 3
#define ET_RIGHT 4
#define ET_PAGELEFT 5
#define ET_PAGERIGHT 6
byte evtType = ET_NONE;
#define BTN_LEFT_PIN 7
#define BTN_RIGHT_PIN 5
#define BTN_ENTER_PIN 6
char *tags[] = {
"NONE", // 0
"BACK", // 1
"SELECT", // 2
"LEFT", // 3
"RIGHT", // 4
"PAGELEFT", // 5
"PAGERIGHT", // 6
};
#define LONG_TRIGGER 250
// Button Instances
EasyButton btnLeft(BTN_LEFT_PIN); // EasyButton btnLeft(int BTN_LEFT_PIN, uint32 debounce, bool pullup, invert);
EasyButton btnRight(BTN_RIGHT_PIN);
EasyButton btnEnter(BTN_ENTER_PIN);
// Button Callbacks
//
void onBtnLeftPressed() {
evtType = ET_LEFT;
}
void onBtnRightPressed() {
evtType = ET_RIGHT;
}
void onBtnLeftLongPressed() {
evtType = ET_PAGELEFT;
}
void onBtnRightLongPressed() {
evtType = ET_PAGERIGHT;
}
void onBtnEnterPressed() {
evtType = ET_SELECT;
}
void onBtnEnterLongPressed() {
evtType = ET_BACK;
}
void setup(){
Serial.begin(115200); Serial.println("does not!");
// display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDR); //0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
// display.clearDisplay();
// display.display();
/* ...
display cmds
...
*/
// INIT Buttons !!!
btnLeft.begin();
btnRight.begin();
btnEnter.begin();
// SETUP
btnLeft.onPressed(onBtnLeftPressed);
btnLeft.onPressedFor(LONG_TRIGGER, onBtnLeftLongPressed);
btnRight.onPressed(onBtnRightPressed);
btnRight.onPressedFor(LONG_TRIGGER, onBtnRightLongPressed);
btnEnter.onPressed(onBtnEnterPressed);
btnEnter.onPressedFor(LONG_TRIGGER, onBtnEnterLongPressed);
}
void loop() {
btnLeft.read();
btnRight.read();
btnEnter.read();
if (evtType!=ET_NONE) processEvent();
}
void processEvent(){
// dispatch actions based on EventType
// ...
static int coubter;
Serial.print("event # ");
Serial.print(coubter);
Serial.print(" = ");
Serial.println(tags[evtType]);
coubter++;
// resolve action/event
evtType = ET_NONE;
}