From 1aea8f32dd37a220f74bdb9c09d05f103876fc60 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 11 Oct 2012 15:23:21 +0200 Subject: [PATCH] Scheduler: rename sleep in wait; fixed example --- .../sam/libraries/Scheduler/Scheduler.cpp | 2 +- .../sam/libraries/Scheduler/Scheduler.h | 4 +-- .../MultipleBlinks/MultipleBlinks.ino | 26 +++++++++++-------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/hardware/arduino/sam/libraries/Scheduler/Scheduler.cpp b/hardware/arduino/sam/libraries/Scheduler/Scheduler.cpp index 15027ff10..e2ea3c879 100644 --- a/hardware/arduino/sam/libraries/Scheduler/Scheduler.cpp +++ b/hardware/arduino/sam/libraries/Scheduler/Scheduler.cpp @@ -122,7 +122,7 @@ void yield(void) { coopDoYield(cur); } -void sleep(uint32_t ms) { +void wait(uint32_t ms) { uint32_t start = millis(); while (millis() - start < ms) yield(); diff --git a/hardware/arduino/sam/libraries/Scheduler/Scheduler.h b/hardware/arduino/sam/libraries/Scheduler/Scheduler.h index a5e5fddd6..e4b910225 100644 --- a/hardware/arduino/sam/libraries/Scheduler/Scheduler.h +++ b/hardware/arduino/sam/libraries/Scheduler/Scheduler.h @@ -23,7 +23,7 @@ extern "C" { typedef void (*SchedulerTask)(void); typedef void (*SchedulerParametricTask)(void *); - void sleep(uint32_t ms); + void wait(uint32_t ms); void yield(); } @@ -34,7 +34,7 @@ public: static void start(SchedulerTask task, uint32_t stackSize = 1024); static void start(SchedulerParametricTask task, void *data, uint32_t stackSize = 1024); - static void sleep(uint32_t ms) { ::sleep(ms); }; + static void wait(uint32_t ms) { ::wait(ms); }; static void yield() { ::yield(); }; }; diff --git a/hardware/arduino/sam/libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino b/hardware/arduino/sam/libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino index 5826e7a8c..2581b7283 100644 --- a/hardware/arduino/sam/libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino +++ b/hardware/arduino/sam/libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino @@ -7,7 +7,7 @@ int led2 = 12; int led3 = 11; void setup() { - Serial1.begin(115200); + Serial.begin(115200); // Setup the 3 pins as OUTPUT pinMode(led1, OUTPUT); @@ -25,33 +25,37 @@ void loop() { digitalWrite(led1, HIGH); // IMPORTANT: - // We must use 'sleep' instead of 'delay' to guarantee + // We must use 'wait' instead of 'delay' to guarantee // that the other tasks get executed. - // (sleep passes control to other tasks while waiting) - sleep(1000); + // ('wait' passes control to other tasks while waiting) + wait(1000); digitalWrite(led1, LOW); - sleep(1000); + wait(1000); } // Task no.2: blink LED with 0.1 second delay. void loop2() { digitalWrite(led2, HIGH); - sleep(100); + wait(100); digitalWrite(led2, LOW); - sleep(100); + wait(100); } // Task no.3: accept commands from Serial1 port // '0' turns off LED // '1' turns on LED void loop3() { - if (Serial1.available()) { - char c = Serial1.read(); - if (c=='0') + if (Serial.available()) { + char c = Serial.read(); + if (c=='0') { digitalWrite(led3, LOW); - if (c=='1') + Serial.println("Led turned off!"); + } + if (c=='1') { digitalWrite(led3, HIGH); + Serial.println("Led turned on!"); + } } // IMPORTANT: