Hallo liebe Forummitglieder,
das nachstehende Lernbeispiel
Multiple Blinks
The Scheduler library allows the Arduino Due to manage multiple tasks at the same time. By setting up a number of other functions that run the same way loop() does, it's possible to have separate looping functions without a dedicated timer.
Hardware Required
Arduino Due Board
three LEDs
three 220 ohm resistors
The Circuit
The anode of the LEDs are connected in series with a 220-ohm resistor to pins 11, 12, and 13 on the Due. Their cathodes connect to ground.
Code
// Include Scheduler since we want to manage multiple tasks.
#include <Scheduler.h>
int led1 = 13;
int led2 = 12;
int led3 = 11;
void setup() {
Serial.begin(9600);
// Setup the 3 pins as OUTPUT
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
// Add "loop2" and "loop3" to scheduling.
// "loop" is always started by default.
Scheduler.startLoop(loop2);
Scheduler.startLoop(loop3);
}
// Task no.1: blink LED with 1 second delay.
void loop() {
digitalWrite(led1, HIGH);
// IMPORTANT:
// When multiple tasks are running 'delay' passes control to
// other tasks while waiting and guarantees they get executed.
delay(1000);
digitalWrite(led1, LOW);
delay(1000);
}
// Task no.2: blink LED with 0.1 second delay.
void loop2() {
digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led2, LOW);
delay(100);
}
// Task no.3: accept commands from Serial port
// '0' turns off LED
// '1' turns on LED
void loop3() {
if (Serial.available()) {
char c = Serial.read();
if (c=='0') {
digitalWrite(led3, LOW);
Serial.println("Led turned off!");
}
if (c=='1') {
digitalWrite(led3, HIGH);
Serial.println("Led turned on!");
}
}
// IMPORTANT:
// We must call 'yield' at a regular basis to pass
// control to other tasks.
yield();
}
verursacht folgende fehlermeldung beim Kompilieren:
Arduino: 1.6.5 (Windows 7), Platine: "Arduino Duemilanove or Diecimila, ATmega328"
Build-Optionen wurden verändert, alles wird neu gebaut
Verwende die Bibliothek Scheduler im Ordner: C:\Program Files\Arduino\libraries\Scheduler (legacy)
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -Wall -Wextra -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard -IC:\Program Files\Arduino\libraries\Scheduler C:\Users\Ulrich\AppData\Local\Temp\build2721552012718208815.tmp\Muliple_Blinks.cpp -o C:\Users\Ulrich\AppData\Local\Temp\build2721552012718208815.tmp\Muliple_Blinks.cpp.o
Muliple_Blinks.ino: In function 'void setup()':
Muliple_Blinks.ino:18:11: error: expected unqualified-id before '.' token
Muliple_Blinks.ino:19:11: error: expected unqualified-id before '.' token
expected unqualified-id before '.' token
dabei wird die Zeile: Schedule.startLoop(loop3); als Problemzeile ausgewiesen.
Was muss ich hier verändern?
Vielen dank für Eure Unterstützung im voraus.
LG Umcharly