Skip to content

Commit e4a717a

Browse files
authored
Added Button class
1 parent e3cb63a commit e4a717a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/CircuitsFunBasic.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
#define Rw B00000010 // Read/Write bit
5353
#define Rs B00000001 // Register select bit
5454

55+
#define HIGH 0x1
56+
5557
class LCD : public Print {
5658
public:
5759
LCD();
@@ -128,4 +130,25 @@ void draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixe
128130
uint8_t _backlightval;
129131
};
130132

133+
class Button {
134+
public:
135+
Button(int pin=8,bool pressedValue=HIGH);
136+
void begin();
137+
bool pressed(int timeout=0);
138+
bool released(int timeout=0);
139+
bool doublePressed(int timeout=0,int tolerance=500);
140+
141+
bool isPressed();
142+
virtual bool getState();
143+
144+
protected:
145+
int pin;
146+
bool pressedValue;
147+
bool lastState;
148+
long debounceTime;
149+
bool checkPress(int timeout, bool requiredState);
150+
151+
};
152+
153+
131154
#endif

0 commit comments

Comments
 (0)