Skip to content

Update volatile.adoc: Add explanation to examples #712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 23, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Language/Variables/Variable Scope & Qualifiers/volatile.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ There are several ways to do this:
=== Example Code
// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄

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

[source,arduino]
----
Expand All @@ -77,16 +78,19 @@ void blink() {
}
----

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

[source,arduino]
----
#include <util/atomic.h> // this library includes the ATOMIC_BLOCK macro.
volatile int input_from_interrupt;

void loop() {
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
// code with interrupts blocked (consecutive atomic operations will not get interrupted)
int result = input_from_interrupt;
}
}
----


Expand Down