arduino須要藉助SCoop實現多線程git
GitHub下載地址:https://github.com/fabriceo/SCoopgithub
#include "SCoop.h"
defineTask(Task1);
void Task1::setup()
{
}
void Task1::loop()
{
sleep(1000);
int reading = digitalRead(13);
if(reading == LOW){Serial.println("LOW");}
if(reading == HIGH){Serial.println("HIGH");}
}
void setup() {
mySCoop.start();
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop()
{
yield();
digitalWrite(13, HIGH);
sleep(1000);
digitalWrite(13, LOW);
sleep(1000);
}編程
若是隻是想在某個線程中暫停,請使用sleep(ms)。若使用delay(),則會使整個程序都暫停。多線程