Arduino-Scheduler
Portable Collaborative Multi-Tasking Scheduler for Arduino
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
Debounce.h
Go to the documentation of this file.
1
22
#ifndef DEBOUNCE_H
23
#define DEBOUNCE_H
24
25
template
<
int
PIN,
void
(*CALLBACK)()>
26
class
Debounce
{
27
public
:
28
static
void
setup
()
29
{
30
pinMode(PIN, INPUT_PULLUP);
31
}
32
static
void
loop
()
33
{
34
const
unsigned
int
DEBOUNCE = 50;
35
int
state
= digitalRead(PIN);
36
while
(1) {
37
await
(digitalRead(PIN) != state);
38
unsigned
int
start = millis();
39
if
(state) CALLBACK();
40
unsigned
int
ms = millis() - start;
41
if
(ms < DEBOUNCE) delay(DEBOUNCE - ms);
42
state = !
state
;
43
}
44
}
45
};
46
47
#endif
await
#define await(cond)
Definition:
Scheduler.h:162
Debounce
Definition:
Debounce.h:26
state
volatile int state
Definition:
SchedulerDebounce.ino:49
Debounce::loop
static void loop()
Definition:
Debounce.h:32
Debounce::setup
static void setup()
Definition:
Debounce.h:28
examples
SchedulerDebounceTemplate
Debounce.h
Generated on Thu Aug 31 2017 12:52:29 for Arduino-Scheduler by
1.8.11