NS.One RTOS Blink 4 LED

Berikut adalah sebuah contoh aplikasi NS.One RTOS, menggunakan 4 thread blink LED, yang terhubung dengan pin output yang berbeda.

#include <ChibiOS_AVR.h>

static WORKING_AREA(waThread1, 64);
static msg_t Thread1(void *arg) {
  
  pinMode(31,OUTPUT);
  while (1) {
    chThdSleepMilliseconds(500);
    digitalWrite(31,!digitalRead(31));
  }
  return 0;  
}

static WORKING_AREA(waThread2, 64);
static msg_t Thread2(void *arg) {

  pinMode(30,OUTPUT);
  while (1) {
    chThdSleepMilliseconds(1000);
    digitalWrite(30,!digitalRead(30));
  }
  return 0;  
}

static WORKING_AREA(waThread3, 64);
static msg_t Thread3(void *arg) {
  
  pinMode(29,OUTPUT);
  while (1) {
    chThdSleepMilliseconds(250);
    digitalWrite(29,!digitalRead(29));
  }
  return 0;
}

static WORKING_AREA(waThread4, 64);
static msg_t Thread4(void *arg) {
  
  pinMode(28,OUTPUT);
  while (1) {
    chThdSleepMilliseconds(100);
    digitalWrite(28,!digitalRead(28));
  }
  return 0;  
}

void setup() {
  chBegin(mainThread);
  while(1) {}
}

void mainThread() {

  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1, NULL);
  chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO + 2, Thread2, NULL);
  chThdCreateStatic(waThread3, sizeof(waThread3), NORMALPRIO + 2, Thread3, NULL);
  chThdCreateStatic(waThread4, sizeof(waThread4), NORMALPRIO + 2, Thread4, NULL);
}

void loop() {
// tidak digunakan
}