-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTouchLib.h
More file actions
60 lines (50 loc) · 1.25 KB
/
TouchLib.h
File metadata and controls
60 lines (50 loc) · 1.25 KB
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
#ifndef TouchLib_H
#define TouchLib_H
#include <Arduino.h>
class AnalogTouch // This works on analog inputs that can be digital I/Os as well. (does not work on A6 and A7 of ATMEGA 328P, those are analog only pins!)
{
private:
// User adjustable variables.
byte Pin;
byte CalibrationLimit = 100;
byte Threshold = 15;
// Internal variables
boolean LastState = false;
byte Counter = 0;
unsigned int UntouchedValue;
public:
// Constructor
AnalogTouch(byte AnalogPin);
/* Public Methods */
// Settings
void SetCalibLimit (byte NewLimit);
void SetThreshold (byte NewThreshold);
// Operation
boolean Calibrate ();
byte Read ();
boolean ReadState ();
};
class DigitalTouch // Meant for 16MHz arduinos! Not guaranteed to work correctly on other speeds!
{
private:
// User adjustable variables.
byte Pin;
byte CalibrationLimit = 7;
byte Threshold = 4;
// Internal variables
boolean LastState = false;
byte Counter = 0;
unsigned int UntouchedValue;
public:
// Constructor
DigitalTouch (byte DigitalPin);
/* Public Methods */
// Settings
void SetCalibLimit (byte NewLimit);
void SetThreshold (byte NewThreshold);
// Operation
boolean Calibrate ();
byte Read ();
boolean ReadState ();
};
#endif