Created
November 6, 2019 05:49
-
-
Save khthana/51f423a0ba0088dd85f52ad8e894faf1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino_FreeRTOS.h> | |
#include "queue.h" | |
#define RED 6 | |
#define YELLOW 5 | |
#define SW1 7 | |
#define SW2 8 | |
QueueHandle_t BlinkQueue; | |
void setup() | |
{ | |
Serial.begin(9600); | |
BlinkQueue = xQueueCreate(5, sizeof(int32_t)); | |
xTaskCreate(vSenderTask, "Sender Task 1", 100, SW1, 1, NULL); | |
xTaskCreate(vSenderTask, "Sender Task 1", 100, SW2, 1, NULL); | |
xTaskCreate(vReceiverTask, "Receiver Task", 100, NULL, 1, NULL); | |
} | |
void vSenderTask(void *pvParameters) | |
{ | |
BaseType_t qStatus; | |
int32_t valueToSend = 0; | |
int SW = (int32_t)pvParameters; | |
pinMode(SW, INPUT); | |
const TickType_t xTicksToWait = pdMS_TO_TICKS(100); | |
while (1) | |
{ | |
if (digitalRead(SW) == HIGH) | |
valueToSend = SW; | |
else | |
valueToSend = 0; | |
if (valueToSend != 0) { | |
qStatus = xQueueSend(BlinkQueue, &valueToSend, xTicksToWait); | |
if (qStatus != pdPASS) | |
{ | |
Serial.println("Could not send to the queue"); | |
} | |
vTaskDelay(100); | |
} | |
} | |
} | |
void vReceiverTask(void *pvParameters) | |
{ | |
int32_t valueReceived; | |
BaseType_t qStatus; | |
const TickType_t xTicksToWait = pdMS_TO_TICKS(100); | |
pinMode(RED, OUTPUT); digitalWrite(RED, HIGH); | |
pinMode(YELLOW, OUTPUT); digitalWrite(YELLOW, HIGH); | |
while (1) | |
{ | |
qStatus = xQueueReceive(BlinkQueue, &valueReceived, xTicksToWait); | |
if (qStatus != pdPASS) | |
{ | |
Serial.println("Could not receive from queue "); | |
} | |
else | |
{ | |
Serial.print("Received value : "); | |
Serial.println(valueReceived); | |
if (valueReceived == 7) { | |
digitalWrite(RED, LOW); | |
vTaskDelay(100); | |
digitalWrite(RED, HIGH); | |
} else if (valueReceived == 8) { | |
digitalWrite(YELLOW, LOW); | |
vTaskDelay(100); | |
digitalWrite(YELLOW, HIGH); | |
} else { | |
vTaskDelay(1); | |
} | |
} | |
} | |
} | |
void loop() {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment