piatok, 24 marec 2017 11:33 Written by 4189 times
Rate this item
(1 Vote)

ARDUINO - Použitie FREE RTOS

V tomto článku si ukážeme ako použiť FREE RTOS v arduino. Rozblikame si 2 LEDky paralelne. Jednou budeme blikať každých 300ms a druhou 1000ms. Vyzerá to jednoducho? Skúste si to bez FreeRTOS.

 

V prvom kroku si nainštalujem FreeRTOS knižnicu do Arduina:

 

Sketch -> Include Library -> Manage Libraries

 

ob1

ob2

 

Zapojíme si naše arduino nano podľa obrázka nižšie:

ob3

 

Kód v cpp:

 

#include <Arduino_FreeRTOS.h>

void setup()
{
  xTaskCreate(
    TaskBlink
    ,  (const portCHAR *)"Blink" 
    ,  128  // Stack size
    ,  NULL
    ,  2  // priority
    ,  NULL );

  xTaskCreate(
    TaskBlink2
    ,  (const portCHAR *)"Blink2"
    ,  128  // Stack size
    ,  NULL
    ,  2  // priority
    ,  NULL );

}

void loop()
{
  

}
void TaskBlink2(void *pvParameters)  // This is a task.
{
  (void) pvParameters;

 
  pinMode(3, OUTPUT);

  for (;;) 
  {
    digitalWrite(3, HIGH);   // turn the LED on (HIGH is the voltage level)
    vTaskDelay( 300 / portTICK_PERIOD_MS ); // wait for one second
    digitalWrite(3, LOW);    // turn the LED off by making the voltage LOW
    vTaskDelay( 300 / portTICK_PERIOD_MS ); // wait for one second
  }
}
void TaskBlink(void *pvParameters)  // This is a task.
{
  (void) pvParameters;
 
  pinMode(2, OUTPUT);

  for (;;) 
  {
    digitalWrite(2, HIGH);   // turn the LED on (HIGH is the voltage level)
    vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
    digitalWrite(2, LOW);    // turn the LED off by making the voltage LOW
    vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
  }
}

 

 

Last modified on pondelok, 27 marec 2017 10:41
Ing.Jaroslav Vadel

Som zakladateľom www.projectik.eu.

Hrám sa na programátora, ktorý ovláda:

c#,cpp,java,unity3d,php,html,NI testand,NI Vision Builder,Cognex In-Sight,NI LabView

"Naprogramovať program, ktorý funguje vie každy. Ale to, že program funguje ešte neznamena, že je napísany správne "

Website: www.projectik.eu