Arduino - 多线程库 SCoop 应用 并发处理任务

【库文件下载地址】 

 

1.完整定义。

#include "SCoop.h"
//完整定义
defineTask(TaskTest);
void TaskTest::setup()
{
// put your setup code here, to run once:
}
void TaskTest::loop()
{
  Serial.println(11111);
  sleep(1000);
}

defineTask(TaskTest1);
void TaskTest1::setup()
{
// put your setup code here, to run once:
}
void TaskTest1::loop()
{
  Serial.println(22222);
  sleep(500);
}

void setup(){
  mySCoop.start();
  Serial.begin(9600);
}
void loop(){
  yield();
}

2.快速定义

#include "SCoop.h"

//快速定义
defineTaskLoop(TaskTest){
  Serial.println(11111);
  sleep(1000);
}

defineTaskLoop(Tasktest1){
  Serial.println(2222);
  sleep(100);
}
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  mySCoop.start();
}

void loop() {
  // put your main code here, to run repeatedly:
 yield();
}

参考文章:https://blog.csdn.net/wuli_dear_wang/article/details/80463369

你可能感兴趣的:(arduino,arduino)