Arduino-Scheduler
Portable Collaborative Multi-Tasking Scheduler for Arduino
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"));
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 
52 {
53  pinMode(BUTTON, INPUT_PULLUP);
54 }
55 
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 }
void debounceSetup()
const int BUTTON
#define await(cond)
Definition: Scheduler.h:162
void setup()
void buttonUp()
volatile int state
void debounceLoop()
void loop()
unsigned int count
void buttonDown()
SchedulerClass Scheduler
Definition: Scheduler.cpp:53
static bool start(func_t taskSetup, func_t taskLoop, size_t stackSize=DEFAULT_STACK_SIZE)
Definition: Scheduler.cpp:76