-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #91 and #88 #124
Merged
Merged
Fix #91 and #88 #124
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5e7791b
Add getPressedMs()
IhorNehrutsa 50ff504
Create LongPressEvents.ino
IhorNehrutsa 71c446f
Add setLongPressIntervalMs(ms)
IhorNehrutsa 15461c6
Update LongPressEvents.ino
IhorNehrutsa 1e8dda5
Merge remote-tracking branch 'upstream/master' into fix_91
IhorNehrutsa 808d1d5
Fix the typo: _long_press_intrval_ms => _long_press_interval_ms.
IhorNehrutsa 0b105d2
getPressedTicks() -> getPressedMs()
IhorNehrutsa 4f0db02
Update LongPressEvents.ino
IhorNehrutsa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "OneButton.h" | ||
|
||
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO_EVERY) | ||
// Example for Arduino UNO with input button on pin 2 | ||
#define PIN_INPUT 2 | ||
|
||
#elif defined(ESP8266) | ||
// Example for NodeMCU with input button using FLASH button on D3 | ||
#define PIN_INPUT D3 | ||
|
||
#elif defined(ESP32) | ||
// Example pin assignments for a ESP32 board | ||
// Some boards have a BOOT switch using GPIO 0. | ||
#define PIN_INPUT 0 | ||
|
||
#endif | ||
|
||
// Setup a new OneButton on pin PIN_INPUT | ||
// The 2. parameter activeLOW is true, because external wiring sets the button to LOW when pressed. | ||
OneButton button(PIN_INPUT, true); | ||
|
||
// In case the momentary button puts the input to HIGH when pressed: | ||
// The 2. parameter activeLOW is false when the external wiring sets the button to HIGH when pressed. | ||
// The 3. parameter can be used to disable the PullUp . | ||
// OneButton button(PIN_INPUT, false, false); | ||
|
||
// setup code here, to run once: | ||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Serial.println("\nOneButton Example."); | ||
Serial.println("Please press and hold the button for a few seconds."); | ||
|
||
// link functions to be called on events. | ||
button.attachLongPressStart(LongPressStart, &button); | ||
button.attachDuringLongPress(DuringLongPress, &button); | ||
button.attachLongPressStop(LongPressStop, &button); | ||
|
||
button.setLongPressIntervalMs(1000); | ||
} // setup | ||
|
||
|
||
// main code here, to run repeatedly: | ||
void loop() | ||
{ | ||
// keep watching the push button: | ||
button.tick(); | ||
|
||
// You can implement other code in here or just wait a while | ||
delay(10); | ||
} // loop | ||
|
||
|
||
// this function will be called when the button started long pressed. | ||
void LongPressStart(void *oneButton) | ||
{ | ||
Serial.print(((OneButton *)oneButton)->getPressedMs()); | ||
Serial.println("\t - LongPressStart()"); | ||
} | ||
|
||
// this function will be called when the button is released. | ||
void LongPressStop(void *oneButton) | ||
{ | ||
Serial.print(((OneButton *)oneButton)->getPressedMs()); | ||
Serial.println("\t - LongPressStop()\n"); | ||
} | ||
|
||
// this function will be called when the button is held down. | ||
void DuringLongPress(void *oneButton) | ||
{ | ||
Serial.print(((OneButton *)oneButton)->getPressedMs()); | ||
Serial.println("\t - DuringLongPress()"); | ||
} | ||
|
||
// End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the typo: _long_press_intrval_ms => _long_press_interval_ms