/*
程序: 使用Task Notification来取代Binary Semaphore
API:
xTaskNotifyGive // 相当于精简化的 xTaskNotify() + eIncrement
ulTaskNotifyTake // waitting for notification, then reset to 0
公众号:孤独的二进制
*/
TaskHandle_t xflashLED = NULL;
void flashLED(void *pvParam) {
uint32_t ulNotificationValue;
pinMode(23, OUTPUT);
while (1) {
//返回运行此命令之前的Notification Value
//命令含义: waitting for notification, then reset
ulNotificationValue = ulTaskNotifyTake(pdTRUE, //pdTRUE 运行完后,清零
portMAX_DELAY);
if ( ulNotificationValue > 0 )
{
digitalWrite(23, !digitalRead(23));
vTaskDelay(1000);
}
}
}
void readBtn(void *pvParam) {
pinMode(22, INPUT_PULLUP);
while (1) {
if (digitalRead(22) == LOW) {
//命令含义,相当于精简化的 xTaskNotify() + eIncrement
xTaskNotifyGive(xflashLED);
vTaskDelay(120); //button debounce
}
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
xTaskCreate(flashLED, "Flash LED", 1024 * 4, NULL, 1, &xflashLED);
xTaskCreate(readBtn, "Read Button", 1024 * 4, NULL, 1, NULL);
}
void loop() {
}