Learn to Program in Arduino C.pdf

(3695 KB) Pobierz
Learn to Program
in Arduino™ C:
18 Lessons, from setup() to robots
William P. Osborne holds a BSEE and an MIT (master's degree in teaching) from
Seattle University and an MBA and an MS from Stanford University. His career has
included consulting to technology manufacturers, running a small software company,
and ten years at the Microsoft Corporation, primarily in the Windows operating sys-
tem division. He teaches computer science and engineering at a public high school.
© Copyright 2017, William P. Osborne
Earlier versions of this book were shared on the author's website, LearnCSE.com.
Printed in the United States of America
Published by Armadillo Books
Printed by CreateSpace
ISBN: 978-0-9981287-1-9
Edited by Margo Paddock
Book design by Margo Paddock
Cover design by Abby Osborne
Photographs by Abby Osborne and Caroline Osborne
Although the electronic design of the Arduino
boards is open source (Creative Com-
mons CC-SA-BY License) the Arduino
name, logo, and the graphic design of its
boards are protected trademarks of Arduino LLC (USA).
Introduction
The Arduino™ is an extremely popular single-board computer that can be used to make a vast va-
riety of intelligent devices. With this book you will learn how to work with the Arduino™ itself, to
identify and control common electronic components used with an Arduino,™ and, most important
of all, to write programs for the Arduino.™
This book is for you if you want to understand, program, and use the Arduino™ to make things
that work. It is also for you if you want to teach Arduino™ programming. We believe this mastery
is valuable for three reasons:
1. Industry demands and career opportunity: The key component of the Arduino™ is a mi-
crocontroller from the Atmel Corporation. Learning to program and apply an Arduino™
is also learning to program and apply a microcontroller, a skill that is in heavy demand in
industry.
2. As a basis for learning other programming languages: The Arduino™ is programmed in a
version of the C programming language. Consequently, knowledge of the syntax of Ardu-
ino™ C transfers to learning higher-level languages, including C++, C#, Java, and Python,
which are all currently used in industry.
3. Satisfaction and fun: The Arduino™ can be used as the computing component for many
different kinds of devices. Students who have completed the lessons in this book have gone
on to design, build, and program robots that walk, sensors that record and report data,
musical instruments, and quadcopters that fly, among other things.
You will guide and pace your own learning. Each lesson builds upon and extends the content of
the preceding lessons. And each lesson is constructed as it would be presented in a classroom, be-
ginning first with key concepts and ending with exercises in applying that knowledge:
Big Idea: The major concept or skill the lesson conveys. Everything else in the lesson supports
this idea.
Background: The underlying theory, and, when appropriate, the science behind the content
of the lesson. Understanding the background of new material enhances your ability to apply
that knowledge.
Vocabulary: New terms are highlighted in yellow when they introduced in text. Those terms
and their definitions are also conveniently arranged in a table (with a yellow banner heading)
for reference.
Description: Further detail of the concepts covered in the lesson and other information that
will put the lesson's procedure and exercises into the context of the Big Idea.
Goals: The specific set of concepts you will learn and skills you will develop while completing
the lesson.
Materials: A list of the electronic materials and tools used in the lesson. Each item on the list
has a number linking it to a Parts Catalog (available at LearnCSE.com), which provides infor-
mation about where the part can be purchased.
Procedure: A set of ordered steps for conducting the experiment or building the project that
illustrates the content of the lesson.
Exercise(s): A set of one or more additional experiments or projects you can do in order to
apply and reinforce what you have learned in the lesson.
Support in the form of sample programs (referred to as "sketches") for the Arduino,™ FAQs, the
Parts Catalog, new topics and projects, and a blog can be found at
www.LearnCSE.com.
The lessons in this book have been classroom tested. Students have created projects of their own
designs based on what they've learned with earlier versions of these lessons. They have made model
helicopters and airplanes, elaborate rolling robots, musical instruments, light panels, keyboards to
drive synthesizers, "laser" tag games, hover boards, Segway-like vehicles, and more.
Whether you are exploring this book for yourself or to teach others, I hope you find the content
engaging and useful. I invite you to share your thoughts, suggestions, and cool projects of your
own. Visit us anytime at
www.LearnCSE.com.
Learn to Program in Arduino
TM
C:
18 Lessons, from setup() to robots
Lesson
LESSONS 1
Lesson 1: Microcontrollers and SBCs
Microcontrollers and SBCs
1
The Big Idea:
This book is about computer science.
It is not about the Arduino,™ the C programming language, electronic components, or the mathe-
matics of electricity—even though we refer to them extensively in the lessons in this book.
The Arduino,™ the C programming language, electronic components, and
the mathematics of electricity are the
tools
this book uses to teach computer
science.
These tools allow readers to learn by doing, to learn with their hands. Every lesson is either an ex-
periment or a project. Some projects, lighting LEDs, for example, are simple. Others are complex.
Laser tag is an excellent example. But simple or complex, none of the projects does anything unless
some computer science has been applied to bring them to life.
Background: What, precisely, is computer science?
For the purposes of this text, computer science is the application of numbers and logic to make
devices, algorithms, and languages that, together, can model just about anything. This book uses
the tools listed in Table 1-1.
Table 1-1. Tools this book uses
Tool Description
devices
The Arduino™ family of Single-Board Computers (SBCs).
algorithms
The collection of programming techniques, tools, and libraries we use to
build our models.
language
The C programming language.
Lesson 1
Microcontrollers and SBCs
Zgłoś jeśli naruszono regulamin