2
// Please read Bounce.h for information about the liscence and authors
8
Bounce::Bounce(uint8_t pin,unsigned long interval_millis)
10
interval(interval_millis);
11
previous_millis = millis();
12
state = digitalRead(pin);
17
void Bounce::write(int new_state)
19
this->state = new_state;
20
digitalWrite(pin,state);
24
void Bounce::interval(unsigned long interval_millis)
26
this->interval_millis = interval_millis;
27
this->rebounce_millis = 0;
30
void Bounce::rebounce(unsigned long interval)
32
this->rebounce_millis = interval;
41
return stateChanged = 1;
44
// We need to rebounce, so simulate a state change
46
if ( rebounce_millis && (millis() - previous_millis >= rebounce_millis) ) {
47
previous_millis = millis();
49
return stateChanged = 1;
52
return stateChanged = 0;
56
unsigned long Bounce::duration()
58
return millis() - previous_millis;
68
// Protected: debounces the pin
69
int Bounce::debounce() {
71
uint8_t newState = digitalRead(pin);
72
if (state != newState ) {
73
if (millis() - previous_millis >= interval_millis) {
74
previous_millis = millis();
84
// The risingEdge method is true for one scan after the de-bounced input goes from off-to-on.
85
bool Bounce::risingEdge() { return stateChanged && state; }
86
// The fallingEdge method it true for one scan after the de-bounced input goes from on-to-off.
87
bool Bounce::fallingEdge() { return stateChanged && !state; }