Arduino-Scheduler
Portable Collaborative Multi-Tasking Scheduler for Arduino
SchedulerChannel.ino
Go to the documentation of this file.
1 
23 #include <Scheduler.h>
24 #include <Scheduler/Channel.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("SchedulerChannel: started"));
38  Serial.flush();
39 
44 }
45 
46 void loop()
47 {
48  static unsigned int count = 0;
49  Serial.print(millis());
50  Serial.print(F(":loop:count="));
51  Serial.println(count++);
52  unsigned long start = millis();
53  await(millis() - start >= 1000);
54 }
55 
56 struct msg_t {
57  int ref;
58  unsigned int nr;
59 };
60 
62 {
63  msg_t msg = { (int) &msg, 0 };
64  while (1) {
65  Serial.print(millis());
66  Serial.print(F(":messageSender#"));
67  Serial.print(msg.ref);
68  Serial.print(F("::send msg.nr="));
69  Serial.println(msg.nr);
70  chan.send(&msg, sizeof(msg));
71  msg.nr += 1;
72  delay(random(500));
73  }
74 }
75 
77 {
78  msg_t msg;
79  chan.recv(&msg, sizeof(msg));
80  Serial.print(millis());
81  Serial.print(F(":messageReceiver#"));
82  Serial.print((int) &msg);
83  Serial.print(F("::receive msg.ref="));
84  Serial.print(msg.ref);
85  Serial.print(F(", msg.nr="));
86  Serial.println(msg.nr);
87  delay(random(1000));
88 }
unsigned int nr
int recv(void *buf, size_t size)
Definition: Channel.h:71
static bool startLoop(func_t taskLoop, size_t stackSize=DEFAULT_STACK_SIZE)
Definition: Scheduler.h:65
#define await(cond)
Definition: Scheduler.h:162
void setup()
void loop()
void messageSender()
int send(const void *buf, size_t size)
Definition: Channel.h:46
unsigned long count
void messageReceiver()
SchedulerClass Scheduler
Definition: Scheduler.cpp:53
Channel chan