// Untuk keperluan demo, hanya core 1 yang kami gunakan
#if CONFIG_FREERTOS_UNICORE
static const BaseType_t app_cpu = 0;
#else
static const BaseType_t app_cpu = 1;
#endif
//LED rates
static const int rate_1 = 500; // ms
static const int rate_2 = 323; // ms
//Pins
static const int led_pin = 23;
//task_1: blink an LED at one rate
void toggleLED_1(void *parameter){
while(1){
digitalWrite(led_pin, HIGH);
vTaskDelay(rate_1/portTICK_PERIOD_MS);
digitalWrite(led_pin, LOW);
vTaskDelay(rate_1/portTICK_PERIOD_MS);
}
}
//TASK_2: Blink LED at another rate
void toggleLED_2(void *parameter){
while(1){
digitalWrite(led_pin, HIGH);
vTaskDelay(rate_2/portTICK_PERIOD_MS);
digitalWrite(led_pin, LOW);
vTaskDelay(rate_2/portTICK_PERIOD_MS);
}
}
void setup() {
// Konfigurasi pin LED
pinMode(led_pin, OUTPUT);
// task yang berjalan terus
xTaskCreatePinnedToCore( // membuat task
toggleLED_1, // fungsi yang akan dipanggil
"Toggle 1", // nama task
1024, // Stack size (bytes in ESP32, words in FreeRTOS)
NULL, // parameter to pass function
1, // Task Priority
NULL, // Task Handle
app_cpu); // Run on one core for demo purposes (ESP32 only)
// task to run forever
xTaskCreatePinnedToCore( // Use xTaskCreate() in vanilla FreeRTOS
toggleLED_2, // Function to be called
"Toggle 2", // 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() {
// put your main code here, to run repeatedly:
//delay(10); // this speeds up the simulation
}