-
Notifications
You must be signed in to change notification settings - Fork 0
/
RichUNOTouchSensor.h
55 lines (45 loc) · 1.07 KB
/
RichUNOTouchSensor.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
#ifndef _RichUNO_TOUCHSENSOR_H__
#define _RichUNO_TOUCHSENSOR_H__
#include <Arduino.h>
class TouchSensor{
private:
int out[4];
public:
TouchSensor(int out1, int out2, int out3, int out4)
{
out[0] = out1;
out[1] = out2;
out[2] = out3;
out[3] = out4;
for(unsigned int i=0; i < 4; i++){
pinMode(out[i], INPUT);
digitalWrite(out[i], HIGH);
}
}
int get()
{
for(unsigned int i=0; i < 4; i++){
if(digitalRead(out[i])){
delay(10);
if(digitalRead(out[i])) return out[i];
}
}
return -1;
}
int getLongPress()
{
for(unsigned int i=0; i < 4; i++){
if(digitalRead(out[i])){
for(unsigned int j=0; j < 150; j++){
delay(20);
if(digitalRead(out[i]) == LOW) return - 1;
}
return out[i];
}
}
}
};
#endif
/*********************************************************************************************************
END FILE
*********************************************************************************************************/