3
3
* https://www.freertos.org/Embedded-RTOS-Queues.html
4
4
*/
5
5
6
- // Include Arduino FreeRTOS library
7
- #include < Arduino_FreeRTOS .h>
6
+ # include < Arduino.h >
7
+ #include < Adafruit_TinyUSB .h> // for Serial
8
8
9
9
// Include queue support
10
10
#include < queue.h>
@@ -17,6 +17,18 @@ QueueHandle_t integerQueue;
17
17
18
18
void setup () {
19
19
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
+
20
32
/* *
21
33
* Create a queue.
22
34
* https://www.freertos.org/a00116.html
@@ -56,7 +68,33 @@ void setup() {
56
68
57
69
}
58
70
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
+ }
60
98
61
99
62
100
/* *
@@ -67,6 +105,9 @@ void loop() {}
67
105
void TaskAnalogRead (void *pvParameters)
68
106
{
69
107
(void ) pvParameters;
108
+
109
+ Serial.print (" Starting task " );
110
+ Serial.println (pcTaskGetName (NULL )); // Get task name
70
111
71
112
for (;;)
72
113
{
@@ -91,13 +132,8 @@ void TaskAnalogRead(void *pvParameters)
91
132
void TaskSerial (void * pvParameters) {
92
133
(void ) pvParameters;
93
134
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
101
137
102
138
int valueFromQueue = 0 ;
103
139
@@ -122,13 +158,16 @@ void TaskBlink(void *pvParameters)
122
158
{
123
159
(void ) pvParameters;
124
160
161
+ Serial.print (" Starting task " );
162
+ Serial.println (pcTaskGetName (NULL )); // Get task name
163
+
125
164
pinMode (LED_BUILTIN, OUTPUT);
126
165
127
166
for (;;)
128
167
{
129
168
digitalWrite (LED_BUILTIN, HIGH);
130
- vTaskDelay ( 250 / portTICK_PERIOD_MS );
169
+ vTaskDelay ( 250 / ( 1 + portTICK_PERIOD_MS) );
131
170
digitalWrite (LED_BUILTIN, LOW);
132
- vTaskDelay ( 250 / portTICK_PERIOD_MS );
171
+ vTaskDelay ( 250 / ( 1 + portTICK_PERIOD_MS) );
133
172
}
134
173
}
0 commit comments