#if CONFIG_FREERTOS_UNICORE
#define ARDUINO_RUNNING_CORE 0
#else
#define ARDUINO_RUNNING_CORE 1
#endif
void LedR( void *pvParameters );
void LedG( void *pvParameters );
void LedB( void *pvParameters );
void TaskAnalogReadA3( void *pvParameters );
void setup() {
Serial.begin(115200);
xTaskCreatePinnedToCore(
LedR
, "pwmRED"
, 1024
, NULL
, 2
, NULL
, ARDUINO_RUNNING_CORE);
xTaskCreatePinnedToCore(
LedG
, "pwmGREEN"
, 1024
, NULL
, 2
, NULL
, ARDUINO_RUNNING_CORE);
xTaskCreatePinnedToCore(
LedB
, "pwmBLUE"
, 1024
, NULL
, 2
, NULL
, ARDUINO_RUNNING_CORE);
xTaskCreatePinnedToCore(
TaskAnalogReadA3
, "AnalogReadA3"
, 1024
, NULL
, 1
, NULL
, ARDUINO_RUNNING_CORE);
}
void loop()
{
// Empty. Things are done in Tasks.
}
/*--------------------------------------------------*/
/*---------------------- Tasks ---------------------*/
/*--------------------------------------------------*/
void LedR(void *pvParameters)
{
(void) pvParameters;
pinMode(25, OUTPUT);
for (;;)
{
analogWrite(25, 255);
vTaskDelay(500);
analogWrite(25, 255);
vTaskDelay(500);
analogWrite(25, 100);
vTaskDelay(500);
}
}
void LedG(void *pvParameters)
{
(void) pvParameters;
pinMode(26, OUTPUT);
for (;;)
{
analogWrite(26, 50);
vTaskDelay(300);
analogWrite(26, 100);
vTaskDelay(300);
analogWrite(26, 50);
vTaskDelay(300);
}
}
void LedB(void *pvParameters)
{
(void) pvParameters;
pinMode(27, OUTPUT);
for (;;)
{
analogWrite(27, 10);
vTaskDelay(200);
analogWrite(27, 100);
vTaskDelay(200);
analogWrite(27, 255);
vTaskDelay(200);
}
}
void TaskAnalogReadA3(void *pvParameters) // This is a task.
{
(void) pvParameters;
for (;;)
{
int sensorValueA3 = analogRead(A6);
Serial.println(sensorValueA3);
vTaskDelay(10);
}
}