Skip to content

Commit 0650027

Browse files
authored
Update volatile.adoc: Add explanation to examples
This change also adds a visual separator between the two code blocks so it is clear that they do not belong together.
1 parent 8076217 commit 0650027

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Language/Variables/Variable Scope & Qualifiers/volatile.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ There are several ways to do this:
5555
=== Example Code
5656
// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄
5757

58+
Use a `volatile byte` to store the pin state in a single byte:
5859

5960
[source,arduino]
6061
----
@@ -77,16 +78,19 @@ void blink() {
7778
}
7879
----
7980

81+
Use an atomic block for atomic access to a 16-bit `int`:
8082

8183
[source,arduino]
8284
----
8385
#include <util/atomic.h> // this library includes the ATOMIC_BLOCK macro.
8486
volatile int input_from_interrupt;
8587
88+
void loop() {
8689
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
8790
// code with interrupts blocked (consecutive atomic operations will not get interrupted)
8891
int result = input_from_interrupt;
8992
}
93+
}
9094
----
9195

9296

0 commit comments

Comments
 (0)