Arduino-Scheduler
Portable Collaborative Multi-Tasking Scheduler for Arduino
SchedulerEventQueue.ino
Go to the documentation of this file.
1 
23 #include <Scheduler.h>
24 #include <Scheduler/Queue.h>
25 
26 // Check for SparkFun SAMD21 Breakout
27 #if defined(ARDUINO_ARCH_SAMD) && (USB_PID == 0x8D21)
28 #define Serial SerialUSB
29 #endif
30 
32 
33 void setup()
34 {
35  Serial.begin(57600);
36  while (!Serial);
37  Serial.println(F("SchedulerEventQueue: started"));
38  Serial.flush();
39 
40  // Start two event handlers
43 }
44 
45 void loop()
46 {
47  // Push events
48  static unsigned int event = 0;
49  Serial.print(millis());
50  Serial.print(F(":loop::push event="));
51  Serial.println(event);
52  eventq.push(&event);
53  event += 1;
54 
55  // Random processing time
56  delay(random(500));
57 }
58 
60 {
61  // Pull events
62  unsigned int event;
63  eventq.pull(&event);
64  Serial.print(millis());
65  Serial.print(F(":eventHandler#"));
66  Serial.print((int) &event);
67  Serial.print(F("::pull event="));
68  Serial.println(event);
69 
70  // Random service time
71  delay(random(1000));
72 }
Queue< unsigned int, 8 > eventq
void pull(T *data)
Definition: Queue.h:90
void push(const T *data)
Definition: Queue.h:64
static bool startLoop(func_t taskLoop, size_t stackSize=DEFAULT_STACK_SIZE)
Definition: Scheduler.h:65
Definition: Queue.h:28
Event event
void setup()
void eventHandler()
SchedulerClass Scheduler
Definition: Scheduler.cpp:53
void loop()