Arduino-Scheduler
Portable Collaborative Multi-Tasking Scheduler for Arduino
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
SchedulerDebounce.ino
Go to the documentation of this file.
1
23
#include <
Scheduler.h
>
24
25
// Check for SparkFun SAMD21 Breakout
26
#if defined(ARDUINO_ARCH_SAMD) && (USB_PID == 0x8D21)
27
#define Serial SerialUSB
28
#endif
29
30
unsigned
int
count
= 0;
31
32
void
setup
()
33
{
34
Serial.begin(57600);
35
while
(!Serial);
36
Serial.println(F(
"SchedulerDebounce: started"
));
37
Scheduler
.
start
(
debounceSetup
,
debounceLoop
);
38
}
39
40
void
loop
()
41
{
42
Serial.print(millis());
43
Serial.print(F(
":loop::count="
));
44
Serial.println(
count
);
45
delay(1000);
46
}
47
48
const
int
BUTTON
= 4;
49
volatile
int
state
;
50
51
void
debounceSetup
()
52
{
53
pinMode(
BUTTON
, INPUT_PULLUP);
54
}
55
56
void
debounceLoop
()
57
{
58
const
unsigned
int
DEBOUNCE = 50;
59
state
= digitalRead(
BUTTON
);
60
while
(1) {
61
await
(digitalRead(
BUTTON
) !=
state
);
62
state
= !
state
;
63
if
(
state
)
64
buttonUp
();
65
else
66
buttonDown
();
67
delay(DEBOUNCE);
68
}
69
}
70
71
void
buttonDown
()
72
{
73
Serial.print(millis());
74
Serial.println(F(
":buttonDown"
));
75
count
+= 1;
76
}
77
78
void
buttonUp
()
79
{
80
Serial.print(millis());
81
Serial.println(F(
":buttonUp"
));
82
}
debounceSetup
void debounceSetup()
Definition:
SchedulerDebounce.ino:51
BUTTON
const int BUTTON
Definition:
SchedulerDebounce.ino:48
await
#define await(cond)
Definition:
Scheduler.h:162
setup
void setup()
Definition:
SchedulerDebounce.ino:32
buttonUp
void buttonUp()
Definition:
SchedulerDebounce.ino:78
state
volatile int state
Definition:
SchedulerDebounce.ino:49
debounceLoop
void debounceLoop()
Definition:
SchedulerDebounce.ino:56
loop
void loop()
Definition:
SchedulerDebounce.ino:40
count
unsigned int count
Definition:
SchedulerDebounce.ino:30
buttonDown
void buttonDown()
Definition:
SchedulerDebounce.ino:71
Scheduler
SchedulerClass Scheduler
Definition:
Scheduler.cpp:53
SchedulerClass::start
static bool start(func_t taskSetup, func_t taskLoop, size_t stackSize=DEFAULT_STACK_SIZE)
Definition:
Scheduler.cpp:76
Scheduler.h
examples
SchedulerDebounce
SchedulerDebounce.ino
Generated on Thu Aug 31 2017 12:52:29 for Arduino-Scheduler by
1.8.11