Skip to content

Commit

Permalink
added M5Stack Core2 exmaple
Browse files Browse the repository at this point in the history
  • Loading branch information
LennartHennigs committed May 21, 2022
1 parent 3640b8a commit 4ee4b02
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Unreleased
- **Note:** Unreleased changes are checked in but not part of an official release (available through the Arduino IDE or PlatfomIO) yet. This allows you to test WiP features and give feedback to them.
-
## [2.0.3] - 2022-05-21
- Added example for the [M5Stack Core2](https://github.com/LennartHennigs/Button2/blob/master/examples/M5StackCore2CustomHandler/M5StackCore2CustomHandler.ino) - showing how to add a custom handler for the touch buttons

## [2.0.1] - 2022-04-22
- Fixed bug – `longclick_detected_counter` is not properly initalized as mentioned in [#37](https://github.com/LennartHennigs/Button2/pull/37)
Expand Down
97 changes: 97 additions & 0 deletions examples/M5StackCore2CustomHandler/M5StackCore2CustomHandler.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#include "M5Core2.h"
#include "Button2.h"

/////////////////////////////////////////////////////////////////

Button2 button;
bool cleared = false;

/////////////////////////////////////////////////////////////////
byte myButtonStateHandler() {
return !(M5.BtnA.isPressed());
}

/////////////////////////////////////////////////////////////////

void setup() {
M5.begin();

button.setDoubleClickTime(300);

// button.setChangedHandler(changed);
// button.setPressedHandler(pressed);
button.setReleasedHandler(released);

// button.setTapHandler(tap);
button.setClickHandler(click);
button.setLongClickDetectedHandler(longClickDetected);
// button.setLongClickHandler(longClick);

button.setDoubleClickHandler(doubleClick);
button.setTripleClickHandler(tripleClick);

button.setButtonStateFunction(myButtonStateHandler);
button.begin(VIRTUAL_PIN);

M5.Lcd.clear();
M5.Lcd.setTextSize(2);
M5.Lcd.setTextWrap(true, true);
M5.Lcd.print("Button A Test");
M5.Lcd.print("\n");
M5.Lcd.print("\n");
}

void loop() {
button.loop();
// clear screen if wrap happened
if (M5.Lcd.getCursorY() <= 16) {
if (!cleared) {
M5.Lcd.clear();
Serial.println("now");
cleared = true;
}
} else {
cleared = false;
}
M5.update();
}

/////////////////////////////////////////////////////////////////

void pressed(Button2& btn) {
M5.Lcd.print("pressed");
M5.Lcd.print("\n");
}
void released(Button2& btn) {
M5.Lcd.print("released: ");
M5.Lcd.print(btn.wasPressedFor());
M5.Lcd.print("\n");
}
void changed(Button2& btn) {
M5.Lcd.print("changed");
M5.Lcd.print("\n");
}
void click(Button2& btn) {
M5.Lcd.print("click");
M5.Lcd.print("\n");
}
void longClickDetected(Button2& btn) {
M5.Lcd.print("long click detected");
M5.Lcd.print("\n");
}
void longClick(Button2& btn) {
M5.Lcd.print("long click");
M5.Lcd.print("\n");
}
void doubleClick(Button2& btn) {
M5.Lcd.print("double click");
M5.Lcd.print("\n");
}
void tripleClick(Button2& btn) {
M5.Lcd.print("triple click\n");
M5.Lcd.print("\n");
}
void tap(Button2& btn) {
M5.Lcd.print("tap");
M5.Lcd.print("\n");
}

0 comments on commit 4ee4b02

Please sign in to comment.