#define LED_TASK_PRIORITY 1
#define BUTTON_TASK_PRIORITY 2
// Deklarasi Handle Tugas
TaskHandle_t xLedTaskHandle;
TaskHandle_t xButtonTaskHandle;
static const int button_pin = 15;
//
void LED_task(void *parameter){
pinMode(LED_BUILTIN, OUTPUT);
while(1){
vTaskDelay(500 / portTICK_PERIOD_MS);
digitalWrite(LED_BUILTIN, HIGH);
vTaskDelay(500 / portTICK_PERIOD_MS);
digitalWrite(LED_BUILTIN, LOW);
}
}
// Fungsi tugas tombol
void button_task(void *parameter){
pinMode(button_pin, INPUT_PULLUP);
while (1) {
int buttonState = digitalRead(button_pin);
if (buttonState == LOW) {
vTaskSuspend(xLedTaskHandle);
Serial.println("Suspend");
} else{
vTaskResume(xLedTaskHandle);
Serial.println("Resume");
}
vTaskDelay(pdMS_TO_TICKS(200));
}
}
void setup() {
//set up serial
Serial.begin(9600);
// memanggil function LED task
xTaskCreatePinnedToCore(
LED_task, "LED", 1024, NULL, LED_TASK_PRIORITY, &xLedTaskHandle, 0);
// memanggil function button task
xTaskCreatePinnedToCore(
button_task, "ButtonTask", 1024, NULL, BUTTON_TASK_PRIORITY,
&xButtonTaskHandle, 0);
vTaskDelete(NULL);
}
loop(){
}