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.
2 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)
3 Long random(min, max)Serial CommunicationUsed for communication between the Arduino board and a== (equal to)!= (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.
4 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. 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.
5 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)!= (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)
6 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()
7 Serial (speed)int ()int () () (data) (data)Utilitiescast (cast operator)sizeof() (sizeof operator)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.
8 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)LCD 4 Bit - control LCDs (using 4 data lines)
9 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.
10 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. 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++) {.}