Example: biology

Arduino - Reference

ArduinoBuy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog | Forum | Playground Reference Language (extended) | Libraries | Comparison | BoardLanguage ReferenceSee the extended Reference for more advanced features of the Arduino languages and the libraries page for interfacingwith particular types of programs can be divided in three main parts: structure, values (variables and constants), and functions. The Arduinolanguage is based on C/C++.StructureAn Arduino program run in two parts:void setup()void loop()setup() is preparation, and loop() is execution. In the setupsection, always at the top of your program, you would setpinModes, initialize serial communication, etc. The loopsection is the code to be executed -- reading inputs,triggering outputs, DeclarationFunction DeclarationvoidControl whilebreakcontinuereturnFurther Syntax; (semicolon){} (curly braces)// (single line comment)/* */ (multi-line comment)Arithmetic Operators+ (addition)- (subtraction)* (multiplication)/ (division)% (modulo)Comparison OperatorsFunctionsDigital I/OpinMode(pin, mode)digitalWrite(pin, value)int digitalRead(pin)Analog I/Oint analogRead(pin)analogWrite(pin, value) - PWMA dvanced I/OshiftOut(dataPin, clockPin, bitOrder, value)unsigned long pulseIn(pin, value)Timeunsigned long millis()delay(ms)delayMicroseconds(us)Ma thmin(x, y)max(x, y)abs(x)constrain(x, a, b)map(value, fromLow, fromHigh, toLow, toHigh)pow(base, exponent)sqrt(x)Trigo

For a guide to writing your own libraries, see this tutorial. Reference Home Corrections, suggestions, and new documentation should be posted to the Forum. The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

Tags:

  Guide, Arduino, Reference, Arduino reference

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Arduino - Reference

1 ArduinoBuy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog | Forum | Playground Reference Language (extended) | Libraries | Comparison | BoardLanguage ReferenceSee the extended Reference for more advanced features of the Arduino languages and the libraries page for interfacingwith particular types of programs can be divided in three main parts: structure, values (variables and constants), and functions. The Arduinolanguage is based on C/C++.StructureAn Arduino program run in two parts:void setup()void loop()setup() is preparation, and loop() is execution. In the setupsection, always at the top of your program, you would setpinModes, initialize serial communication, etc. The loopsection is the code to be executed -- reading inputs,triggering outputs, DeclarationFunction DeclarationvoidControl whilebreakcontinuereturnFurther Syntax; (semicolon){} (curly braces)// (single line comment)/* */ (multi-line comment)Arithmetic Operators+ (addition)- (subtraction)* (multiplication)/ (division)% (modulo)Comparison OperatorsFunctionsDigital I/OpinMode(pin, mode)digitalWrite(pin, value)int digitalRead(pin)Analog I/Oint analogRead(pin)analogWrite(pin, value) - PWMA dvanced I/OshiftOut(dataPin, clockPin, bitOrder, value)unsigned long pulseIn(pin, value)Timeunsigned long millis()delay(ms)delayMicroseconds(us)Ma thmin(x, y)max(x, y)abs(x)constrain(x, a, b)map(value, fromLow, fromHigh, toLow, toHigh)pow(base, exponent)sqrt(x)Trigonometrysin(rad)cos( rad)tan(rad)Random NumbersrandomSeed(seed)long random(max)long random(min, max)Serial CommunicationUsed for communication between the Arduino board and a== (equal to)!

2 = (not equal to)< (less than)> (greater than)<= (less than or equal to)>= (greater than or equal to)Boolean Operators&& (and)|| (or)! (not)Compound Operators++ (increment)-- (decrement)+= (compound addition)-= (compound subtraction)*= (compound multiplication)/= (compound division)VariablesVariables are expressions that you can use in programs tostore values, such as a sensor reading from an analog are particular values with specific | LOWINPUT | OUTPUT true | falseInteger ConstantsData TypesVariables can have various types, which are described intlongunsigned longfloatdoublestringarrayReferenceASCII chartcomputer or other devices. This communication happens viathe Arduino board's serial or USB connection and on digitalpins 0 (RX) and 1 (TX). Thus, if you use these functions,you cannot also use pins 0 and 1 for digital (speed)int ()int () () (data) (data)Didn't find something? Check the extended Reference orthe HomeCorrections, suggestions, and new documentation should be posted to the text of the Arduino Reference is licensed under a Creative Commons Attribution-ShareAlike License.

3 Code samples inthe Reference are released into the public Page | Page History | Printable View | All Recent Site ChangesArduinoBuy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog | Forum | Playground Reference Language (extended) | Libraries | Comparison | BoardArduino Reference (extended)The Arduino language is based on C/C++ and supports all standard C constructs and some C++ features. It links against AVRLibc and allows the use of any of its functions; see its user manual for Arduino , the standard program entry point (main) isdefined in the core and calls into two functions in a () is called once, then loop() is called repeatedly(until you reset your board).void setup()void loop()Control whilebreakcontinuereturnFurther Syntax; (semicolon){} (curly braces)// (single line comment)/* */ (multi-line comment)#define#includeArithmetic Operators+ (addition)- (subtraction)* (multiplication)/ (division)% (modulo)Comparison Operators== (equal to)!

4 = (not equal to)< (less than)> (greater than)<= (less than or equal to)>= (greater than or equal to)FunctionsDigital I/OpinMode(pin, mode)digitalWrite(pin, value)int digitalRead(pin)Analog I/OanalogReference(type)int analogRead(pin)analogWrite(pin, value) - PWMA dvanced I/OshiftOut(dataPin, clockPin, bitOrder, value)unsigned long pulseIn(pin, value)Timeunsigned long millis()delay(ms)delayMicroseconds(us)Ma thmin(x, y)max(x, y)abs(x)constrain(x, a, b)map(value, fromLow, fromHigh, toLow, toHigh)pow(base, exponent)sqrt(x)Trigonometrysin(rad)cos( rad)tan(rad)Random NumbersrandomSeed(seed)long random(max)long random(min, max)External InterruptsattachInterrupt(interrupt, function, mode)detachInterrupt(interrupt)Boolean Operators&& (and)|| (or)! (not)Pointer Access Operators* dereference operator& Reference operatorBitwise Operators& (bitwise and)| (bitwise or)^ (bitwise xor)~ (bitwise not)<< (bitshift left)>> (bitshift right)Port ManipulationCompound Operators++ (increment)-- (decrement)+= (compound addition)-= (compound subtraction)*= (compound multiplication)/= (compound division)&= (compound bitwise and)|= (compound bitwise or)VariablesConstantsHIGH | LOWINPUT | OUTPUT true | falseinteger constantsfloating point constantsData Typesvoid keywordbooleancharunsigned charbyteintunsigned intlongunsigned longfloatdoublestringarrayVariable Scope & QualifiersstaticvolatileconstPROGMEMI nterruptsinterrupts()noInterrupts()Seria l (speed)int ()int () () (data) (data)Utilitiescast (cast operator)sizeof() (sizeof operator)

5 ReferencekeywordsASCII chartAtmega168 pin mappingReference HomeCorrections, suggestions, and new documentation should be posted to the text of the Arduino Reference is licensed under a Creative Commons Attribution-ShareAlike License. Code samples inthe Reference are released into the public Page | Page History | Printable View | All Recent Site ChangesArduinoBuy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog | Forum | Playground Reference Language (extended) | Libraries | Comparison | BoardLibrariesTo use an existing library in a sketch, go to the Sketch menu, choose "Import Library", and pick from the libraries will insert one or more #include statements at the top of the sketch and allow it to use the libraries are uploaded to the board with your sketch, they increase the amount of space it takes up. If a sketch nolonger needs a library, simply delete its #include statements from the top of your LibrariesThese are the "official" libraries that are included in the Arduino - reading and writing to "permanent" storageSoftwareSerial - for serial communication on any digital pinsStepper - for controlling stepper motorsWire - Two Wire Interface (TWI/I2C) for sending and receiving data over a net of devices or libraries are compatible Wiring versions, and the links below point to the (excellent) Wiring - Basic LED Matrix display manipulation librarySprite - Basic image sprite manipulation library for use in animations with an LED matrixContributed LibrariesLibraries written by members of the Arduino - a library for keeping track of the current date and time in - for communicating with applications on the computer using a standard serial - graphics routines for LCD based on the KS0108 or equivalent - control LCDs (using 8 data lines)

6 LCD 4 Bit - control LCDs (using 4 data lines)LedControl - for controlling LED matrices or seven-segment displays with a MAX7221 or - an alternative to the Matrix library for driving multiple LEDs with Maxim - handle stringsMetro - help you time actions at regular intervalsMsTimer2 - uses the timer 2 interrupt to trigger an action every N - control devices (from Dallas Semiconductor) that use the One Wire - read characters from a PS2 - provides software support for Servo motors on any - provides hardware support for Servo motors on pins 9 and 10 Simple Message System - send messages between Arduino and the computerSSerial2 Mobile - send text messages or emails using a cell phone (via AT commands over software serial)X10 - Sending X10 signals over AC power linesTo install, unzip the library to a sub-directory of the hardware/libraries sub-directory of the Arduino application launch the Arduino environment; you should see the library in the Import Library a guide to writing your own libraries, see this HomeCorrections, suggestions, and new documentation should be posted to the text of the Arduino Reference is licensed under a Creative Commons Attribution-ShareAlike License.

7 Code samples inthe Reference are released into the public Page | Page History | Printable View | All Recent Site ChangesArduinoBuy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog | Forum | Playground Reference Language (extended) | Libraries | Comparison | BoardArduino/Processing Language ComparisonThe Arduino language (based on Wiring) is implemented in C/C++, and therefore has some differences from the Processinglanguage, which is based on bar[8]; bar[0] = 1;int[] bar = new int[8]; bar[0] = 1;int foo[] = { 0, 1, 2 };int foo[] = { 0, 1, 2 }; or int[] foo = { 0, 1, 2 };LoopsArduinoProcessingint i; for (i = 0; i < 5; i++) { .. }for (int i = 0; i < 5; i++) { .. } ("hello world");println("hello world");int i = 5; (i);int i = 5; println(i);int i = 5; ("i = "); (i); ();int i = 5; println("i = " + i); Reference HomeCorrections, suggestions, and new documentation should be posted to the text of the Arduino Reference is licensed under a Creative Commons Attribution-ShareAlike License.

8 Code samples inthe Reference are released into the public Page | Page History | Printable View | All Recent Site ChangesArduinoBuy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog | Forum | Playground Reference Language (extended) | Libraries | Comparison | BoardIntroduction to the Arduino BoardLooking at the board from the top down, this is an outline of what you will see (parts of the board you might interact with inthe course of normal use are highlighted):Starting clockwise from the top center:Analog Reference pin (orange)Digital Ground (light green)Digital Pins 2-13 (green)Digital Pins 0-1/Serial In/Out - TX/RX (dark green) - These pins cannot be used for digital i/o (digitalRead anddigitalWrite) if you are also using serial communication ( ).Reset Button - S1 (dark blue)In-circuit Serial Programmer (blue-green)Analog In Pins 0-5 (light blue)Power and Ground Pins (power: orange, grounds: light orange)External Power Supply In (9-12 VDC) - X1 (pink)Toggles External Power and USB Power (place jumper on two pins closest to desired supply) - SV1 (purple)USB (used for uploading sketches to the board and for serial communication between the board and the computer.)

9 Can be used to power the board) (yellow)MicrocontrollersATmega168 (used on most Arduino boards)Digital I/O Pins14 (of which 6 provide PWM output)Analog Input Pins6 (DIP) or 8 (SMD)DC Current per I/O Pin40 mAATmega8 (used on some older board)Digital I/O Pins14 (of which 3 provide PWM output)Analog Input Pins6DC Current per I/O Pin40 mAFlash Memory16 KBSRAM1 KBEEPROM512 bytes(datasheet)Flash Memory8 KBSRAM1 KBEEPROM512 bytes(datasheet)Digital PinsIn addition to the specific functions listed below, the digital pins on an Arduino board can be used for general purpose inputand output via the pinMode(), digitalRead(), and digitalWrite() commands. Each pin has an internal pull-up resistor which canbe turned on and off using digitalWrite() (w/ a value of HIGH or LOW, respectively) when the pin is configured as an maximum current per pin is 40 : 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. On the Arduino Diecimila, thesepins are connected to the corresponding pins of the FTDI USB-to-TTL Serial chip.

10 On the Arduino BT, they areconnected to the corresponding pins of the WT11 Bluetooth module. On the Arduino Mini and LilyPad Arduino , theyare intended for use with an external TTL serial module ( the Mini-USB Adapter).External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low value, a rising or fallingedge, or a change in value. See the attachInterrupt() function for : 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function. On boards with anATmega8, PWM output is available only on pins 9, 10, and Reset: 7. ( Arduino BT-only) Connected to the reset line of the bluetooth : 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication, which, although providedby the underlying hardware, is not currently included in the Arduino : 13. On the Diecimila and LilyPad, there is a built-in LED connected to digital pin 13. When the pin is HIGH value, the LED is on, when the pin is LOW, it's PinsIn addition to the specific functions listed below, the analog input pins support 10-bit analog-to-digital conversion (ADC) usingthe analogRead() function.


Related search queries