Arduino programing handbook

Solo disponible en BuenasTareas
  • Páginas : 11 (2651 palabras )
  • Descarga(s) : 0
  • Publicado : 1 de febrero de 2012
Leer documento completo
Vista previa del texto
arduino programming notebook

brian w. evans

Arduino Programming Notebook Written and compiled by Brian W. Evans

With information or inspiration taken from:

Including material written by: Paul Badger Massimo Banzi Hernando Barragán David Cuartielles Tom IgoeDaniel Jolliffe Todd Kurt David Mellis and others

Published: First Edition August 2007 Second Edition September 2008

12c bao
This work is licensed under the Creative Commons Attribution-Share Alike 2.5 License. To view a copy of this license, visit: Or send a letter to: Creative Commons 171 Second Street, Suite 300 San Francisco, California, 94105,USA


structure structure setup() loop() functions {} curly braces ; semicolon /*… */ block comments // line comments variables variables variable declaration variable scope datatypes byte int long float arrays arithmetic arithmetic compound assignments comparison operators logical operators constants constants true/false high/low input/output 16 16 16 16 14 14 15 15 12 12 12 12 1310 10 11 7 7 7 8 8 9 9 9

flow control if if… else for while do… while digital i/o pinMode(pin, mode) digitalRead(pin) digitalWrite(pin, value) analog i/o analogRead(pin) analogWrite(pin, value) time delay(ms) millis() math min(x, y) max(x, y) random randomSeed(seed) random(min, max) serial Serial.begin(rate) Serial.println(data) appendix digital output digital input high current output pwmoutput potentiometer input variable resistor input servo output 29 30 31 32 33 34 35 26 26 25 25 24 24 24 24 23 23 21 22 22 17 18 19 20 20


This notebook serves as a convenient, easy to use programming reference for the command structure and basic syntax of the Arduino microcontroller. To keep it simple, certain exclusions were made that make this a beginner’s reference best used as asecondary source alongside other websites, books, workshops, or classes. This decision has lead to a slight emphasis on using the Arduino for standalone purposes and, for example, excludes the more complex uses of arrays or advanced forms of serial communication. Beginning with the basic structure of Arduino's C derived programming language, this notebook continues on to describe the syntax of themost common elements of the language and illustrates their usage with examples and code fragments. This includes many functions of the core library followed by an appendix with sample schematics and starter programs. The overall format compliments O’Sullivan and Igoe’s Physical Computing where possible. For an introduction to the Arduino and interactive design, refer to Banzi’s Getting Startedwith Arduino, aka the Arduino Booklet. For the brave few interested in the intricacies of programming in C, Kernighan and Ritchie’s The C Programming Language, second edition, as well as Prinz and Crawford’s C in a Nutshell, provide some insight into the original programming syntax. Above all else, this notebook would not have been possible without the great community of makers and shear mass oforiginal material to be found at the Arduino website, playground, and forum at

The basic structure of the Arduino programming language is fairly simple and runs in at least two parts. These two required parts, or functions, enclose blocks of statements. void setup() { statements; } void loop() { statements; } Where setup() is the preparation, loop() is theexecution. Both functions are required for the program to work. The setup function should follow the declaration of any variables at the very beginning of the program. It is the first function to run in the program, is run only once, and is used to set pinMode or initialize serial communication. The loop function follows next and includes the code to be executed continuously – reading inputs,...
tracking img