Skip to content

Arduino library for providing a consistent critical section interface over various Arduino platforms.

License

Notifications You must be signed in to change notification settings

107-systems/107-Arduino-CriticalSection

Repository files navigation

💾 107-Arduino-CriticalSection

Arduino Library Badge Compile Examples Arduino Lint keywords.txt Checks General Formatting Checks Spell Check

This library provides a consistent critical section interface over various Arduino platforms.

This library works for

Example

#include <107-Arduino-CriticalSection.h>

volatile int button_evt_counter = 0;

void setup() {
  Serial.begin(9600);
  while (!Serial) { }

  attachInterrupt(0, onButton_1_Pressed, RISING);
  attachInterrupt(1, onButton_2_Pressed, RISING);
}

void loop() {
  int copy_button_evt_counter;
  {
    /* Prevent change of button_evt_counter during readout. */
    CriticalSection crit_sec;
    copy_button_evt_counter = button_evt_counter;
  }
  Serial.println(copy_button_evt_counter);
}

void onButton_1_Pressed() {
  CriticalSection crit_sec;
  button_evt_counter++;
}

void onButton_2_Pressed() {
  CriticalSection crit_sec;
  button_evt_counter++;
}

About

Arduino library for providing a consistent critical section interface over various Arduino platforms.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published