From 2d429e75ce69e77f8c95490ac03881ec9aa0354a Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 25 Oct 2010 21:15:28 -0400 Subject: arduino language reference nearing completion, properly CC-BY-SA 3.0 attributed --- source/arduino/include.rst | 88 ++++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 31 deletions(-) (limited to 'source/arduino/include.rst') diff --git a/source/arduino/include.rst b/source/arduino/include.rst index 6d53801..da124e5 100644 --- a/source/arduino/include.rst +++ b/source/arduino/include.rst @@ -1,42 +1,68 @@ +.. highlight:: cpp + .. _arduino-include: #include ======== -**#include** is used to include outside libraries in your sketch. +``#include`` is used to include outside libraries in your sketch. This gives the programmer access to a large group of standard C -libraries (groups of pre-made functions), and also libraries -written especially for Arduino. - - - -The main reference page for AVR C libraries (AVR is a reference to -the Atmel chips on which the Arduino is based) is -`here. `_ - - - -Note that **#include**, similar to **#define**, has no semicolon -terminator, and the compiler will yield cryptic error messages if -you add one. - - +libraries (groups of pre-made functions and data types), and also +libraries written especially for Maple. Example ------- -This example includes a library that is used to put data into the -program space *flash* instead of *ram*. This saves the ram space -for dynamic memory needs and makes large lookup tables more -practical. - - - -:: - - #include - - prog_uint16_t myConstants[] PROGMEM = {0, 21140, 702 , 9128, 0, 25764, 8456, - 0,0,0,0,0,0,0,0,29810,8968,29762,29762,4500}; - +This example (from the `Arduino LiquidCrystal Tutorial +`_) includes a library +that is used to control :ref:`LCD displays `:: + + // include the library code: + #include + + // initialize the library with the numbers of the interface pins + LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + + void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); + } + + void loop() { + // set the cursor to column 0, line 1 + // (note: line 1 is the second row, since counting begins with 0): + lcd.setCursor(0, 1); + // print the number of seconds since reset: + lcd.print(millis()/1000); + } + +Note that a ``#include`` line, like :ref:`#define `, +has **no semicolon**. The compiler will print strange error messages +if you add one. + +C Standard Library +------------------ + +The standard C library that comes with Maple is called `newlib +`_. Its main sources of documentation +are its `main reference `_ +page and its `math functions +`_ reference page. Here's an +example that imports the math.h library in order to take the `cube +root `_ of a number:: + + #include + + void setup() { + // no setup necessary + } + + void loop() { + // "cbrt" stands for "cube root" + double cubeRootOf3 = cbrt(3.0); + // prints a number that is approximately the cube root of 3: + SerialUSB.println(cubeRootOf3); + } -- cgit v1.2.3