arduino_cookbook.pdf

(19576 KB) Pobierz
SECOND EDITION
Arduino Cookbook
Michael Margolis
Beijing
Cambridge
Farnham
Köln
Sebastopol
Tokyo
Arduino Cookbook, Second Edition
by Michael Margolis
Copyright © 2012 Michael Margolis, Nicholas Weldin. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (http://my.safaribooksonline.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or
corporate@oreilly.com.
Editors:
Shawn Wallace and Brian Jepson
Production Editor:
Teresa Elsey
Proofreader:
Kiel Van Horn
March 2011:
December 2011:
First Edition.
Second Edition.
Indexer:
Lucie Haskins
Cover Designer:
Karen Montgomery
Interior Designer:
David Futato
Illustrator:
Robert Romano
Revision History for the Second Edition:
2011-12-09
First release
2013-05-17
Second release
See
http://oreilly.com/catalog/errata.csp?isbn=9781449313876
for release details.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc.
Arduino Cookbook,
the image of a toy rabbit, and related trade dress are trademarks
of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
ISBN: 978-1-449-31387-6
[LSI]
1368725222
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
1. Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Installing the Integrated Development Environment (IDE)
1.2 Setting Up the Arduino Board
1.3 Using the Integrated Development Environment (IDE) to Prepare
an Arduino Sketch
1.4 Uploading and Running the Blink Sketch
1.5 Creating and Saving a Sketch
1.6 Using Arduino
4
8
10
13
14
17
2. Making the Sketch Do Your Bidding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
2.10
2.11
2.12
2.13
2.14
2.15
2.16
2.17
2.18
2.19
Structuring an Arduino Program
Using Simple Primitive Types (Variables)
Using Floating-Point Numbers
Working with Groups of Values
Using Arduino String Functionality
Using C Character Strings
Splitting Comma-Separated Text into Groups
Converting a Number to a String
Converting a String to a Number
Structuring Your Code into Functional Blocks
Returning More Than One Value from a Function
Taking Actions Based on Conditions
Repeating a Sequence of Statements
Repeating Statements with a Counter
Breaking Out of Loops
Taking a Variety of Actions Based on a Single Variable
Comparing Character and Numeric Values
Comparing Strings
Performing Logical Comparisons
24
25
27
29
32
37
38
41
43
45
49
52
53
55
58
59
61
63
64
iii
Zgłoś jeśli naruszono regulamin