Skip to content

Commit e1fd253

Browse files
committed
Adding basic example to README.
1 parent 01b8fa2 commit e1fd253

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,35 @@ This library works for
2323

2424
### Example
2525
```C++
26+
#include <107-Arduino-CriticalSection.h>
2627

28+
volatile int button_evt_counter = 0;
29+
30+
void setup() {
31+
Serial.begin(9600);
32+
while (!Serial) { }
33+
34+
attachInterrupt(0, onButton_1_Pressed, RISING);
35+
attachInterrupt(1, onButton_2_Pressed, RISING);
36+
}
37+
38+
void loop() {
39+
int copy_button_evt_counter;
40+
{
41+
/* Prevent change of button_evt_counter during readout. */
42+
CriticalSection crit_sec;
43+
copy_button_evt_counter = button_evt_counter;
44+
}
45+
Serial.println(copy_button_evt_counter);
46+
}
47+
48+
void onButton_1_Pressed() {
49+
CriticalSection crit_sec;
50+
button_evt_counter++;
51+
}
52+
53+
void onButton_2_Pressed() {
54+
CriticalSection crit_sec;
55+
button_evt_counter++;
56+
}
2757
```

0 commit comments

Comments
 (0)