File tree Expand file tree Collapse file tree 1 file changed +4
-0
lines changed
Language/Variables/Variable Scope & Qualifiers Expand file tree Collapse file tree 1 file changed +4
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ There are several ways to do this:
55
55
=== Example Code
56
56
// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄
57
57
58
+ Use a `volatile byte` to store the pin state in a single byte:
58
59
59
60
[source,arduino]
60
61
----
@@ -77,16 +78,19 @@ void blink() {
77
78
}
78
79
----
79
80
81
+ Use an atomic block for atomic access to a 16-bit `int`:
80
82
81
83
[source,arduino]
82
84
----
83
85
#include <util/atomic.h> // this library includes the ATOMIC_BLOCK macro.
84
86
volatile int input_from_interrupt;
85
87
88
+ void loop() {
86
89
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
87
90
// code with interrupts blocked (consecutive atomic operations will not get interrupted)
88
91
int result = input_from_interrupt;
89
92
}
93
+ }
90
94
----
91
95
92
96
You can’t perform that action at this time.
0 commit comments