Untitled
unknown
plain_text
9 months ago
1.1 kB
10
Indexable
// Uses only one core for demo
#if CONFIG_FREERTOS_UNICORE
static const BaseType_t app_cpu = 0;
#else
static const BaseType_t app_cpu = 1;
#endif
// Define LED pin (Ubah sesuai board ESP32)
static const int led_pin = 2; // Coba ganti ke 4 atau 5 jika tidak menyala
// Task function: Blink LED
void toggleLED(void *parameter) {
while (1) {
digitalWrite(led_pin, HIGH); // LED ON
vTaskDelay(500 / portTICK_PERIOD_MS);
digitalWrite(led_pin, LOW); // LED OFF
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
void setup() {
// Configure pin as output
pinMode(led_pin, OUTPUT);
// Create FreeRTOS task to toggle LED
xTaskCreatePinnedToCore(
toggleLED, // Function to be called
"Toggle LED", // Name of task
1024, // Stack size (in words)
NULL, // Parameter to pass to function
1, // Task priority (higher number = higher priority)
NULL, // Task handle
app_cpu // Run on the selected core
);
}
void loop() {
// Empty loop since the task runs independently
}Editor is loading...
Leave a Comment