Arduino

아두이노 스레드(Thread) - Simple Thread LED 동작

작성자 임베디드코리아 작성일26-05-24 16:52 조회28회 댓글0건

첨부파일

---> Thread_Simple_LED.ino  <-------------------------------
#include <Thread.h>

/* My simple Thread */
Thread myThread = Thread();

int m_Count = 0;
int ledPin = 13;

/* callback for myThread */
void ledCallback(){
  static bool ledStatus = false;
  ledStatus = !ledStatus;
  digitalWrite(ledPin, ledStatus);

  Serial.print("ledCallback : ");
  Serial.print(millis()); 
}

void setup() {
  Serial.begin(9600);

myThread.onRun(ledCallback);
myThread.setInterval(500);
}

void loop() {
  /* checks if thread should run */
if(myThread.shouldRun())
myThread.run();
 
  ++m_Count;
  Serial.print("Main Thread :  ");
  Serial.println(m_Count);

  delay(1000);
}