aboutsummaryrefslogtreecommitdiffstats
path: root/docs/source/arduino/volatile.rst
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@mit.edu>2010-10-20 06:46:52 -0400
committerMarti Bolivar <mbolivar@mit.edu>2010-10-20 06:46:52 -0400
commit22ff1db8a76c7047b61a424ae1fa5f43697fcb34 (patch)
treebf722c8a5a6bd40e0b33fc4a425e0e5b8b9f4216 /docs/source/arduino/volatile.rst
parentbac6548fe90b0721e191d68df2677beb4b15f60a (diff)
downloadlibrambutan-22ff1db8a76c7047b61a424ae1fa5f43697fcb34.tar.gz
librambutan-22ff1db8a76c7047b61a424ae1fa5f43697fcb34.zip
initial check-in of arduino docs in RST format (converted using wget+pandoc)
Diffstat (limited to 'docs/source/arduino/volatile.rst')
-rw-r--r--docs/source/arduino/volatile.rst70
1 files changed, 70 insertions, 0 deletions
diff --git a/docs/source/arduino/volatile.rst b/docs/source/arduino/volatile.rst
new file mode 100644
index 0000000..4212ac5
--- /dev/null
+++ b/docs/source/arduino/volatile.rst
@@ -0,0 +1,70 @@
+.. _arduino-volatile:
+
+volatile keyword
+================
+
+volatile is a keyword known as a variable *qualifier*, it is
+usually used before the datatype of a variable, to modify the way
+in which the compiler and subsequent program treats the variable.
+
+
+
+Declaring a variable volatile is a directive to the compiler. The
+compiler is software which translates your C/C++ code into the
+machine code, which are the real instructions for the Atmega chip
+in the Arduino.
+
+
+
+Specifically, it directs the compiler to load the variable from RAM
+and not from a storage register, which is a temporary memory
+location where program variables are stored and manipulated. Under
+certain conditions, the value for a variable stored in registers
+can be inaccurate.
+
+
+
+A variable should be declared volatile whenever its value can be
+changed by something beyond the control of the code section in
+which it appears, such as a concurrently executing thread. In the
+Arduino, the only place that this is likely to occur is in sections
+of code associated with interrupts, called an interrupt service
+routine.
+
+
+
+Example
+-------
+
+::
+
+ // toggles LED when interrupt pin changes state
+
+ int pin = 13;
+ volatile int state = LOW;
+
+ void setup()
+ {
+ pinMode(pin, OUTPUT);
+ attachInterrupt(0, blink, CHANGE);
+ }
+
+ void loop()
+ {
+ digitalWrite(pin, state);
+ }
+
+ void blink()
+ {
+ state = !state;
+ }
+
+
+
+See also
+--------
+
+
+- `AttachInterrupt <http://arduino.cc/en/Reference/AttachInterrupt>`_
+
+