-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.h
52 lines (42 loc) · 1.55 KB
/
Button.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
42
43
44
45
46
47
48
49
50
51
52
/*
Buttons class for momentary buttons (not switches).
Created by Timo Raab, April 3, 2018.
v0.1
*/
#ifndef Button_h
#define Button_h
#include "Arduino.h"
class Button {
private:
unsigned char _pin; // Arduino Pin
bool _pullUp; // Use of internal pull up resistor,
// if not pull down is assumend,
// standard: true
bool _execAtRelease; // define function execution time
// (at button press or release)
// standard: true (release)
unsigned int _debounceTime; // software debounce
// standard: 20 ms
void (*_bFunc)(); // function call at button press
// standard: do nothing
bool _await;
public:
// constructor
Button(unsigned char pin);
Button(unsigned char pin, bool pullUp);
Button(unsigned char pin, bool pullUp, bool execAtRelease, unsigned int debounceTime, void (*bFunction)());
Button(unsigned char pin, bool pullUp, bool execAtRelease, unsigned int debounceTime, void (*bFunction)(), bool await);
// set Methods
bool setPullUp(bool pullUp);
bool setExecAtRelease(bool execAtRelease);
bool setDebounceTime(unsigned int debounceTime);
bool setFunction(void (*bFunction)());
// detect if a button is pressed
// par: if function call should be executed
// ret: if button is pressed
bool isPressed(bool execute);
};
// function for internal use only. Standard function call for library
void nullFunction();
#endif
//EOF