반응형
스케줄러
Scheduler 라이브러리를 사용하면 SAM 및 SAMD 아키텍처 (즉, Zero, MKRZero, MKR1000 Board) 및 Due) 기반 Arduino가 동시에 여러 기능을 실행할 수 있습니다. 다시 말해 여러 작업을 서로 방해하지 않고 동시에 실행할 수 있습니다. Arduino sam 및 samd 아키텍처에만 해당됩니다 (Due, Zero ...).
Scheduler 라이브러리를 사용하면 Arduino가 동시에 여러 기능을 실행할 수 있습니다. 이를 통해 서로 방해하지 않고 작업을 수행 할 수 있으며, CPU가 한 작업에서 다른 작업으로 전환하는 협력 스케줄러입니다. 라이브러리에는 작업간에 제어를 전달하는 메서드가 포함되어 있습니다.
이 기능에 대한 문서와 repository를 참고하십시요. Compatibility: 이 라이브러리는 sam, samd 아키텍처와 호환되므로 다음 Arduino 보드에서 사용할 수 있습니다.
- Arduino Due
- Arduino MKR FOX 1200
- Arduino MKR GSM 1400
- Arduino MKR NB 1500
- Arduino MKR VIDOR 4000
- Arduino MKR WAN 1300 (LoRa 연결)
- Arduino MKR WAN 1310
- Arduino MKR WiFi 1010
- Arduino MKR ZERO (사운드, 음악 및 디지털 오디오 데이터 용 I2S 버스 및 SD)
- Arduino MKR1000 WIFI Arduino
- Nano 33 BLE Arduino
- Nano 33 IoT
- Arduino Zero
- Portenta H7
이 라이브러리를 사용하려면 반드시 라이브러리 매니저에서 Sceduler를 검색하여 설치해주어야 합니다. 아래 첨부 이미지를 참고하세요.
헤더파일을 포함해야 합니다.
#include <Scheduler.h>
주의 : 스케줄러 라이브러리 및 관련 기능은 실험적입니다. API가 향후 릴리스에서 변경 될 가능성은 없지만 아직 개발 중입니다.
예제 코드 MultipleBlinks : LED의 양극은 220 옴 저항으로 Due의 핀 11, 12, 13에 직렬로 연결하고 음극은 GND 연결.
// 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();
}
반응형