Skip to content

Commit 019f07a

Browse files
author
Michael Polia
committed
Modifications to the example for demonstrating using integer queues to pass data between tasks.
1 parent c8620e2 commit 019f07a

File tree

1 file changed

+51
-12
lines changed

1 file changed

+51
-12
lines changed

examples/IntegerQueue/IntegerQueue.ino

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* https://www.freertos.org/Embedded-RTOS-Queues.html
44
*/
55

6-
// Include Arduino FreeRTOS library
7-
#include <Arduino_FreeRTOS.h>
6+
#include <Arduino.h>
7+
#include <Adafruit_TinyUSB.h> // for Serial
88

99
// Include queue support
1010
#include <queue.h>
@@ -17,6 +17,18 @@ QueueHandle_t integerQueue;
1717

1818
void setup() {
1919

20+
Serial.begin(115200);
21+
22+
// Wait for a serial port connection to be established before continuing.
23+
// Don't want to miss any debug messages.
24+
while ( !Serial ) delay(10); // for nrf52840 with native usb
25+
26+
Serial.println("STARTING THE APPLICATION.");
27+
28+
29+
// Configure pin 4 as an input and enable the internal pull-up resistor.
30+
pinMode(4, INPUT_PULLUP);
31+
2032
/**
2133
* Create a queue.
2234
* https://www.freertos.org/a00116.html
@@ -56,7 +68,33 @@ void setup() {
5668

5769
}
5870

59-
void loop() {}
71+
void loop() {
72+
73+
static bool firstTime = true;
74+
static int previousDigitalReadValue = -1;
75+
76+
if ( firstTime ) {
77+
Serial.println("Starting loop....");
78+
delay(1000);
79+
80+
firstTime = false;
81+
}
82+
83+
int digitalReadValue = digitalRead (4);
84+
85+
if (digitalReadValue != previousDigitalReadValue) {
86+
if (digitalReadValue == HIGH) {
87+
Serial.println("HIGH");
88+
}
89+
else {
90+
Serial.println("LOW");
91+
}
92+
93+
previousDigitalReadValue = digitalReadValue;
94+
}
95+
96+
delay(1000);
97+
}
6098

6199

62100
/**
@@ -67,6 +105,9 @@ void loop() {}
67105
void TaskAnalogRead(void *pvParameters)
68106
{
69107
(void) pvParameters;
108+
109+
Serial.print("Starting task ");
110+
Serial.println(pcTaskGetName(NULL)); // Get task name
70111

71112
for (;;)
72113
{
@@ -91,13 +132,8 @@ void TaskAnalogRead(void *pvParameters)
91132
void TaskSerial(void * pvParameters) {
92133
(void) pvParameters;
93134

94-
// Init Arduino serial
95-
Serial.begin(9600);
96-
97-
// Wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.
98-
while (!Serial) {
99-
vTaskDelay(1);
100-
}
135+
Serial.print("Starting task ");
136+
Serial.println(pcTaskGetName(NULL)); // Get task name
101137

102138
int valueFromQueue = 0;
103139

@@ -122,13 +158,16 @@ void TaskBlink(void *pvParameters)
122158
{
123159
(void) pvParameters;
124160

161+
Serial.print("Starting task ");
162+
Serial.println(pcTaskGetName(NULL)); // Get task name
163+
125164
pinMode(LED_BUILTIN, OUTPUT);
126165

127166
for (;;)
128167
{
129168
digitalWrite(LED_BUILTIN, HIGH);
130-
vTaskDelay( 250 / portTICK_PERIOD_MS );
169+
vTaskDelay( 250 / (1 + portTICK_PERIOD_MS) );
131170
digitalWrite(LED_BUILTIN, LOW);
132-
vTaskDelay( 250 / portTICK_PERIOD_MS );
171+
vTaskDelay( 250 / (1 + portTICK_PERIOD_MS) );
133172
}
134173
}

0 commit comments

Comments
 (0)