Arduino-Scheduler
Portable Collaborative Multi-Tasking Scheduler for Arduino
SchedulerSemaphore.ino
Go to the documentation of this file.
1 
24 #include <Scheduler.h>
25 #include <Scheduler/Semaphore.h>
26 
27 // Check for SparkFun SAMD21 Breakout
28 #if defined(ARDUINO_ARCH_SAMD) && (USB_PID == 0x8D21)
29 #define Serial SerialUSB
30 #endif
31 
33 
34 void setup()
35 {
36  Serial.begin(57600);
37  while (!Serial);
38  Serial.println(F("SchedulerSemaphore: started"));
40 }
41 
42 void loop()
43 {
44  static unsigned int i = 1;
45  unsigned long start, stop, ms;
46 
47  start = millis();
48  mutex.wait();
49  {
50  stop = millis();
51  ms = stop - start;
52  Serial.print(stop);
53  Serial.print(F(":loop::i="));
54  Serial.print(i);
55  Serial.print(F(", wait="));
56  Serial.println(ms);
57  Serial.flush();
58  delay(100);
59  }
60  mutex.signal();
61  delay(random(300));
62  i += 1;
63 }
64 
65 void loop1()
66 {
67  mutex.wait();
68  {
69  Serial.print(millis());
70  Serial.println(F(":loop1::step-1"));
71  delay(random(100));
72 
73  Serial.print(millis());
74  Serial.println(F(":loop1::step-2"));
75  delay(random(100));
76 
77  Serial.print(millis());
78  Serial.println(F(":loop1::step-3"));
79  Serial.flush();
80  delay(random(100));
81  }
82  mutex.signal();
83 }
void setup()
void loop1()
void wait(unsigned int count=1)
Definition: Semaphore.h:36
static bool startLoop(func_t taskLoop, size_t stackSize=DEFAULT_STACK_SIZE)
Definition: Scheduler.h:65
void loop()
SchedulerClass Scheduler
Definition: Scheduler.cpp:53
void signal(unsigned int count=1)
Definition: Semaphore.h:46
Semaphore mutex