LoginSignup
5
7

More than 5 years have passed since last update.

arduinoでマルチタスク

Last updated at Posted at 2019-03-08

概要

arduinoでマルチタスクやってみた。

写真

mos.jpg

使用したライブラリー

サンプルコード

タスクa,b,cが、それぞれ300ms,600ms,900msで動く。

#include "MOS.h"

void task_a(PTCB tcb)
{
    MOS_Continue(tcb);
    while (1)
    {
        Serial.print("A ");
        Serial.println(millis());
        MOS_Delay(tcb, 300);
    }
}
void task_b(PTCB tcb)
{
    MOS_Continue(tcb);
    while (1)
    {
        Serial.print("B ");
        Serial.println(millis());
        MOS_Delay(tcb, 600);
    }
}
void task_c(PTCB tcb)
{
    MOS_Continue(tcb);
    while (1)
    {
        Serial.print("C ");
        Serial.println(millis());
        MOS_Delay(tcb, 900);
    }
}
void setup()
{
    Serial.begin(115200);
}
void loop()
{
    MOS_Call(task_a);
    MOS_Call(task_b);
    MOS_Call(task_c);
}


以上。

5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7