/* Multitasking Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
/**
* Demo for 02 - Blinky
*
* Toggles the LED on and off in its own task/thread.
*
* Date: December 3, 2020
* Author: Shawn Hymel
* License: 0BSD
*/
// Use only core 1 for demo purposes
#if CONFIG_FREERTOS_UNICORE
static const BaseType_t app_cpu = 0;
#else
static const BaseType_t app_cpu = 1;
#endif
// Pins
static const int led_pin = LED_BUILTIN;
// Our task: blink an LED
void toggleLED(void *parameter) {
while(1) {
digitalWrite(led_pin, HIGH);
vTaskDelay(500 / portTICK_PERIOD_MS);
digitalWrite(led_pin, LOW);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
void setup() {
// Configure pin
pinMode(led_pin, OUTPUT);
// Task to run forever
xTaskCreatePinnedToCore( // Use xTaskCreate() in vanilla FreeRTOS
toggleLED, // Function to be called
"Toggle LED", // Name of task
1024, // Stack size (bytes in ESP32, words in FreeRTOS)
NULL, // Parameter to pass to function
1, // Task priority (0 to configMAX_PRIORITIES - 1)
NULL, // Task handle
app_cpu); // Run on one core for demo purposes (ESP32 only)
// If this was vanilla FreeRTOS, you'd want to call vTaskStartScheduler() in
// main after setting up your tasks.
}
void loop() {
// Do nothing
// setup() and loop() run in their own task with priority 1 in core 1
// on ESP32
}