File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -23,5 +23,35 @@ This library works for
23
23
24
24
### Example
25
25
``` C++
26
+ #include < 107-Arduino-CriticalSection.h>
26
27
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
+ }
27
57
```
You can’t perform that action at this time.
0 commit comments