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:
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.
8486volatile 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
You can’t perform that action at this time.
0 commit comments