Skip to content

Commit ab8673f

Browse files
author
Michael Polia
committed
Modifications to the example for demonstrating interrupt-based task notifications.
1 parent 98cafc0 commit ab8673f

File tree

1 file changed

+47
-6
lines changed

1 file changed

+47
-6
lines changed

examples/Notifications/Notifications.ino

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
https://www.freertos.org/RTOS_Task_Notification_As_Binary_Semaphore.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
/**
1010
Declaring a global TaskHandle for the led task.
@@ -13,8 +13,17 @@ TaskHandle_t taskNotificationHandler;
1313

1414
void setup() {
1515

16+
Serial.begin(115200);
17+
18+
// Wait for a serial port connection to be established before continuing.
19+
// Don't want to miss any debug messages.
20+
while ( !Serial ) delay(10); // for nrf52840 with native usb
21+
22+
Serial.println("STARTING THE APPLICATION.");
23+
24+
1625
// Configure pin 2 as an input and enable the internal pull-up resistor.
17-
pinMode(2, INPUT_PULLUP);
26+
pinMode(4, INPUT_PULLUP);
1827

1928
// Create task for FreeRTOS notification
2029
xTaskCreate(TaskNotification, // Task function
@@ -27,6 +36,30 @@ void setup() {
2736

2837
void loop() {
2938

39+
static bool firstTime = true;
40+
static int previousDigitalReadValue = -1;
41+
42+
if ( firstTime ) {
43+
Serial.println("Starting loop....");
44+
delay(1000);
45+
46+
firstTime = false;
47+
}
48+
49+
int digitalReadValue = digitalRead (4);
50+
51+
if (digitalReadValue != previousDigitalReadValue) {
52+
if (digitalReadValue == HIGH) {
53+
Serial.println("HIGH");
54+
}
55+
else {
56+
Serial.println("LOW");
57+
}
58+
59+
previousDigitalReadValue = digitalReadValue;
60+
}
61+
62+
delay(1000);
3063
}
3164

3265
/*
@@ -36,11 +69,17 @@ void TaskNotification(void *pvParameters)
3669
{
3770
(void) pvParameters;
3871

39-
int digitalPin = 2;
72+
int digitalPin = 4;
73+
74+
75+
int rv = attachInterrupt(digitalPinToInterrupt(digitalPin), digitalPinInterruptHandler, CHANGE);
4076

41-
Serial.begin(9600);
77+
Serial.print("Starting task ");
78+
Serial.print(pcTaskGetName(NULL)); // Get task name
79+
Serial.print(" with rv = ");
80+
Serial.println(rv);
81+
delay(1000);
4282

43-
attachInterrupt(digitalPinToInterrupt(digitalPin), digitalPinInterruptHandler, LOW);
4483

4584
for (;;) {
4685

@@ -53,9 +92,11 @@ void TaskNotification(void *pvParameters)
5392

5493

5594
void digitalPinInterruptHandler() {
95+
Serial.println("digitalPinInterruptHandler()");
5696
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
5797
vTaskNotifyGiveFromISR(taskNotificationHandler, &xHigherPriorityTaskWoken);
5898
if (xHigherPriorityTaskWoken) {
99+
Serial.println("Calling taskYIELD()");
59100
taskYIELD();
60101
}
61102
}

0 commit comments

Comments
 (0)