-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBInput.cpp
More file actions
51 lines (45 loc) · 770 Bytes
/
DBInput.cpp
File metadata and controls
51 lines (45 loc) · 770 Bytes
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
#include "DBInput.h"
DBInput::DBInput ( uint8_t pin, uint8_t delay )
{
_pin = pin;
_dbdelay = delay;
_curstate = digitalRead ( pin );
_dbstate = _curstate;
_just = true;
pinMode ( pin, INPUT_PULLUP );
}
bool DBInput::Poll ( )
{
int reading = digitalRead ( _pin );
unsigned long ts = millis ( );
if ( reading != _curstate )
{
_dbstarttime = ts;
_curstate = reading;
}
else if ( ts - _dbstarttime > _dbdelay )
{
_curstate = reading;
// stable reading
if ( reading != _dbstate )
{
_dbstate = reading;
_just = true;
return true;
}
}
return false;
}
uint8_t DBInput::GetCurrentState ( )
{
return _curstate;
}
uint8_t DBInput::GetDBState ( )
{
if ( _just )
{
_just = false;
return _curstate + 2;
}
else return _curstate;
}