Arduino-Scheduler
Portable Collaborative Multi-Tasking Scheduler for Arduino
SchedulerTaskMax.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 #if defined(ARDUINO_ARCH_AVR)
31 const size_t STACK_SIZE = 64;
32 #else
33 const size_t STACK_SIZE = 128;
34 #endif
35 
36 unsigned long count = 0L;
37 
38 void setup()
39 {
40  Serial.begin(57600);
41  while (!Serial);
42  Serial.println(F("SchedulerTaskMax: started"));
43  Serial.flush();
44 
45  int tasks = 0;
46  while (Scheduler.startLoop(counter, STACK_SIZE)) tasks++;
47  Serial.print(millis());
48  Serial.print(F(":setup::task="));
49  Serial.println(tasks);
50  yield();
51  Serial.print(millis());
52  Serial.print(F(":setup::count="));
53  Serial.println(count);
54 }
55 
56 void loop()
57 {
58  count = 0;
59  unsigned long start = millis();
60  await((millis() - start) >= 1000);
61  Serial.print(millis() - start);
62  Serial.print(F(":loop::count="));
63  Serial.println(count);
64 }
65 
66 void counter()
67 {
68  count += 1;
69  yield();
70 }
const size_t STACK_SIZE
static bool startLoop(func_t taskLoop, size_t stackSize=DEFAULT_STACK_SIZE)
Definition: Scheduler.h:65
#define await(cond)
Definition: Scheduler.h:162
unsigned long count
void counter()
void setup()
SchedulerClass Scheduler
Definition: Scheduler.cpp:53
void yield(void)
Definition: Scheduler.cpp:153
void loop()