-
Notifications
You must be signed in to change notification settings - Fork 4
/
TriggerInput.cpp
63 lines (53 loc) · 1.14 KB
/
TriggerInput.cpp
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
#include "Arduino.h"
#include "TriggerInput.h"
TriggerInput::TriggerInput(uint8_t pin)
{
this->pin = pin;
pinMode(pin, INPUT_PULLUP);
}
//
// void TriggerInput::poll()
//
// Reads the value of the trigger input and sets the class
// variable 'triggered' if the input was triggered on this
// polling cycle. Uses code debouncing.
//
void TriggerInput::poll()
{
if ((millis() - last_debounce_time) > debounce_delay)
{
boolean pin_value = ! digitalRead(this->pin);
if(pin_value && (old_pin_value == false))
{
this->triggered = true;
}
else
{
this->triggered = false;
}
if(old_pin_value != pin_value) last_debounce_time = millis();
this->old_pin_value = pin_value;
}
else
{
this->triggered = false;
}
}
//
// boolean TriggerInput::read()
//
// Reads the value of the trigger input and returns it.
//
boolean TriggerInput::read()
{
return(! digitalRead(this->pin));
}
//
// boolean TriggerInput::setDebounce()
//
// Sets the debounce time, in milliseconds used in TriggerInput::poll()
//
void TriggerInput::setDebounce(uint32_t debounce_delay)
{
this->debounce_delay = debounce_delay;
}