//Created by Barbu Vulc! You'll see blinking LED vs dimming LED!
//FreeRTOS library:
#include <Arduino_FreeRTOS.h>
/*****************************************************************
****************************************************************/
const int
LED1 = 9, //Variables for LEDs:
LED2 = 12; //Variables for LEDs:
/*****************************************************************
****************************************************************/
float
Tsampling = 0.01, // sampling period
tdata = 0; // time data sent to output
int
T0_ms = 10,
T1_ms = 10,
T0ticks = 100,
T1ticks = 2500,
baudRate = 9600; // USER PARAMETER - USB Serial Baud Rate (bps)
/*****************************************************************
****************************************************************/
void setup()
{
Serial.begin(baudRate); //Serial communication initialized! It is needed for 'LED1':
pinMode(LED1, OUTPUT); //LEDs initialization:
pinMode(LED2, OUTPUT); //LEDs initialization:
xTaskCreate(Led1, "LED1", 1000, NULL, 0, NULL); //Tasks for LEDs:
xTaskCreate(Led2, "LED2", 1000, NULL, 1, NULL); //Tasks for LEDs:
}
/***************************************************************************
For every 0-to-255 analog iteration of the silver LED (LED1), ...
... the gold LED (LED2) will blink once!
Task for the 1st LED (silver)!
**************************************************************************/
static void Led1(void* pvParameters)
{
//Variable 'n' initialization:
for(int n = 0; n <= 255; n += 5)
{
Serial.println(n);
analogWrite(LED1, n);
vTaskDelay(T0ticks / portTICK_PERIOD_MS);
}
}
/***************************************************************************
For every 0-to-255 analog iteration of the silver LED (LED1), ...
... the gold LED (LED2) will blink once!
//Task for the 2nd LED (gold)!
**************************************************************************/
static void Led2(void* pvParameters)
{
digitalWrite(LED2, HIGH);
vTaskDelay(T1ticks / portTICK_PERIOD_MS);
digitalWrite(LED2, LOW);
vTaskDelay(T1ticks / portTICK_PERIOD_MS);
}
/***************************************************************************
When FreeRTOS elements are used, we don't need the 'loop' function!
**************************************************************************/
void loop()
{
}
/***************************************************************************
***************************************************************************/