byte ledPin = 21;
byte interruptPin = 22;
volatile byte state = LOW;
SemaphoreHandle_t xCountingSemaphore;
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), ISRcallback, RISING);
xCountingSemaphore = xSemaphoreCreateCounting( 9, 0 );
xTaskCreate(
ISRprocessing, /* Task function. */
"ISRprocessing", /* name of task. */
1000, /* Stack size of task */
NULL, /* parameter of the task */
4, /* priority of the task */
NULL);
}
void loop() {
}
void ISRcallback() {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR( xCountingSemaphore, &xHigherPriorityTaskWoken );
xSemaphoreGiveFromISR( xCountingSemaphore, &xHigherPriorityTaskWoken );
xSemaphoreGiveFromISR( xCountingSemaphore, &xHigherPriorityTaskWoken );
xSemaphoreGiveFromISR( xCountingSemaphore, &xHigherPriorityTaskWoken );
xSemaphoreGiveFromISR( xCountingSemaphore, &xHigherPriorityTaskWoken );
xSemaphoreGiveFromISR( xCountingSemaphore, &xHigherPriorityTaskWoken );
}
void ISRprocessing( void * parameter )
{
Serial.println((char *)parameter);
for(;;){
xSemaphoreTake( xCountingSemaphore, portMAX_DELAY );
Serial.println("ISRprocessing is running");
state = !state;
digitalWrite(ledPin, state);
delay(1000);
}
vTaskDelete( NULL );
}