-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTouchPin.h
78 lines (61 loc) · 1.35 KB
/
TouchPin.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef TouchPin_h
#define TouchPin_h
#include "Arduino.h"
class TouchPin
{
public:
/**
* Initializes pins
*/
TouchPin( int pin );
/**
* Call to calibrate when you expect the button to be in a "stable" state
* and noone holding it.
*/
int calibrate();
/**
* Reads capacitive value of button. Normally not needed
*/
int read();
/**
* Returns true as long as the button is touched. This has no hysteresis.
* Normally you want to use 'isHold' instead.
*/
bool isTouch();
/**
* Returns true as long as the button is held. This uses a hysteresis
*/
bool isHold();
/**
* Returns true once after the button is pushed.
* True is only returned once until the button is released again.
*/
bool isPush();
/**
* Returns true once after the button is clicked (pushed and released).
* True is only returned once after the button is released.
*/
bool isClick();
/**
* Return strength of last touch.
*
* This is the value which would have been returned by last read scaled
* by a factor depending on calibration.
*/
int strength();
/**
* Prints settings of this pin
*/
void printInfo();
private:
unsigned long _touchStart;
int _pin;
int _offset;
int _hysteresis;
int _scale;
int _lastCount;
bool _pushed;
int _read();
long _touchTime();
};
#endif