-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30462d6
commit 1ac905d
Showing
2 changed files
with
36 additions
and
0 deletions.
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
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,35 @@ | ||
#ifndef BUTTONS_FAST_BUTTON_H | ||
#define BUTTONS_FAST_BUTTON_H | ||
|
||
// Like a button, but can respond to very short events. | ||
// No de-bouncing, only generates EVENT_CLICK_SHORT | ||
template<int PIN> | ||
class FastButton : public Looper { | ||
public: | ||
USE_PIN_INPUT(PIN, FastButton<PIN>); | ||
|
||
FastButton(const char* name, enum BUTTON button) : name_(name), button_(button) { | ||
pinMode(PIN, INPUT_PULLUP); | ||
attachInterrupt(PIN, &FastButton::irq, FALLING); | ||
} | ||
|
||
const char* name() override { return name_; } | ||
|
||
void Loop() override { | ||
if (pressed) { | ||
pressed = false; | ||
prop.Event(button_, EVENT_CLICK_SHORT); | ||
} | ||
} | ||
|
||
private: | ||
static void irq() { pressed = true; } | ||
|
||
static volatile bool pressed; | ||
const char* name_; | ||
enum BUTTON button_; | ||
}; | ||
|
||
template<int PIN> volatile bool FastButton<PIN>::pressed = false; | ||
|
||
#endif |