-
Notifications
You must be signed in to change notification settings - Fork 3
/
mButton.h
41 lines (38 loc) · 1.13 KB
/
mButton.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#pragma once
// Switch S2 behaviour
#define __S2_To_HIGH__
//#define __S2_To_LOW__ // default to this, as original
//#define __MULTI_PUSH_S2__
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
/**
* Encapsulate tracking pushes on a normally-open momentary button.
*
* After a call to check(), the button may report that it:
* - wasClicked(): tapped briefly
* - wasHeld(): pressed for a longer period of time (and perhaps still closed)
* The next call to check() will not report on that previous event.
*/
class MomentaryButton {
private:
// Any button press >= HOLD_THRESHOLD milliseconds is considered a hold,
// not a click.
unsigned long holdThreshold;
unsigned long bounceThreshold;
// Was this button pushed (closed) when last checked?
boolean wasClosed;
// When was this button pushed (closed)?
unsigned long closeTimeMillis;
const int pin;
boolean clicked, held; // At last check, was this button clicked (held)?
public:
MomentaryButton(int inputPin);
void setThreshold(unsigned long newThreshold);
void setup();
void check();
boolean wasClicked();
boolean wasHeld();
};