Arduino-Scheduler
Portable Collaborative Multi-Tasking Scheduler for Arduino
SchedulerEvent.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 class Event {
31 public:
35  Event() : m_event(0) {}
36 
42  unsigned int wait()
43  {
44  await(m_event != 0);
45  return (m_event);
46  }
47 
53  void signal(unsigned int value)
54  {
55  await(m_event == 0);
56  m_event = value;
57  yield();
58  }
59 
63  void clear()
64  {
65  m_event = 0;
66  }
67 
68 protected:
69  volatile unsigned int m_event;
70 };
71 
73 
74 void setup()
75 {
76  Serial.begin(57600);
77  while (!Serial);
78  Serial.println(F("SchedulerEvent: started"));
80 }
81 
82 void loop()
83 {
84  static unsigned int i = 1;
85  Serial.print(millis());
86  Serial.print(F(":loop::event="));
87  Serial.println(i);
88  delay(1000);
89  event.signal(i);
90  i += 1;
91  if (i == 0) i = 1;
92 }
93 
95 {
96  unsigned int value = event.wait();
97  Serial.print(millis());
98  Serial.print(F(":eventHandler::event="));
99  Serial.println(value);
100  delay(200);
101  event.clear();
102 }
void clear()
void eventHandler()
static bool startLoop(func_t taskLoop, size_t stackSize=DEFAULT_STACK_SIZE)
Definition: Scheduler.h:65
#define await(cond)
Definition: Scheduler.h:162
void signal(unsigned int value)
unsigned int wait()
volatile unsigned int m_event
void loop()
Event event
SchedulerClass Scheduler
Definition: Scheduler.cpp:53
void yield(void)
Definition: Scheduler.cpp:153
void setup()