1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-17 06:52:18 +01:00

Scheduler: rename sleep in wait; fixed example

This commit is contained in:
Cristian Maglie 2012-10-11 15:23:21 +02:00
parent c21da3bedc
commit 1aea8f32dd
3 changed files with 18 additions and 14 deletions

View File

@ -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();

View File

@ -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(); };
};

View File

@ -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: