#include <Arduino_FreeRTOS.h>
#include "semphr.h"
#define BUTTON 2
SemaphoreHandle_t xBinarySemaphore;
TaskHandle_t xTaskHandle1;
TaskHandle_t xTaskHandle2;
QueueHandle_t queue;
void interruptTimerHandler() {
const char *msg = "Hello Interrupt";
xQueueSendFromISR(queue, &msg, NULL);
}
void interruptButtonHandler() {
const char *msg = "Hello World";
xQueueSendFromISR(queue, &msg, NULL);
}
void setup() {
Serial.begin(9600);
queue = xQueueCreate(10, sizeof(String));
xTaskCreate(displayTask, "displayTask", 256, NULL, 2, &xTaskHandle1);
xTaskCreate(timerTask, "timerTask", 256, NULL, 2, &xTaskHandle2);
attachInterrupt(digitalPinToInterrupt(BUTTON), interruptButtonHandler, CHANGE);
attachInterrupt(1, interruptTimerHandler, CHANGE);
vTaskStartScheduler();
}
void loop() {}
void displayTask(void * pvParameters) {
while (1) {
char *msg;
if (xQueueReceive(queue, &msg, portMAX_DELAY)) {
Serial.println(msg);
}
}
}
void timerTask(void * pvParameters) {
while (1) {
char *msg;
if (xQueueReceive(queue, &msg, portMAX_DELAY)) {
Serial.println(msg);
}
}
}