[smtebooks.eu] JavaScript Robotics_ Building NodeBots 1st Edition.Pdf

(23911 KB) Pobierz
Make: JavaScript Robotics
Rick Waldron, Anna Gerber, David
Resseguie, Emily Rose, Susan Hinton,
Sara Gorecki, Bryan Hughes, Andrew
Fisher, Julian David Duque, Pawel
Szymczykowski, Donovan Buck,
Jonathan Beri, Kassandra Perch,
Raquel Vélez, Lyza Danger Gardner
Make: JavaScript Robotics
by Backstop Media and Rick Waldron Copyright © 2015 Backstop Media, LLC.
All rights reserved.
Printed in Canada.
Published by Maker Media, Inc., 1160 Battery Street East, Suite 125, San
Francisco, California 94111.
Maker Media 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
distributor’s corporate/institutional sales department: 800-998-9938 or
corporate@oreilly.com.
Editor: Brian Jepson
Production Editor: Melanie Yarbrough
Copyeditor: Tracy Brown Hamilton
Proofreader: Jasmine Kwityn
Indexer: Meghan Jones, WordCo Indexing
Interior Designer: David Futato
Cover Designer: Brian Jepson
Cover Photographer: Pawel Szymczykowski
Illustrator: Rebecca Demarest
April 2015: First Edition
Revision History for the First Edition
2015-04-03: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781457186950 for release
details.
The Make logo and Maker Media logo are registered trademarks of Maker
Media, Inc. Make: JavaScript Robotics and related trade dress are trademarks of
Maker 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 Maker 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 preparation of this book, the publisher
and author assume no responsibility for errors or omissions, or for damages
resulting from the use of the information contained herein.
978-1-4571-8695-0
[TI]
Preface
By Rick Waldron
I love programming and I also love making things. When I discovered Chris
Williams’
node-serialport
module (for Node.js), I remember thinking, “Now I
can program the things that I make.” So I did! I contributed an Arduino sketch
that printed a photoresistor sensor value to the open serial port and a small
JavaScript handler program that listened for data and printed a “graph” to the
terminal. Months later, I started contributing to Cam Pedersen’s duino project,
until Julian Gaultier approached me with his JavaScript implementation of the
Firmata protocol. From there, we set out to build a collection of high-level
component classes with one goal: to make it easy and fun to control hardware
with JavaScript. This book will show you what we built and how to use it to
program the things that you make.
While the physical challenges of engineering a hardware project remain the
same as they would for a project programmed in any other language, this book is
going to show you how to think about that hardware in terms of objects that
maintain state and provide control behaviors in the form of intuitively designed
interfaces.
So, how would you verbally describe adding an LED to a project and then
turning it on? You might say, “Connect the LED to ground and pin 9, then turn it
on.” Using the Johnny-Five framework, that would be written as:
// Connect the LED to ground and pin 9
var led = new five.Led(9);
// then turn it on
led.on();
What about connecting a servo and then setting its horn to a specific angle in
degrees? “Attach the servo to pin 10 and position its horn to 110°.” Here’s what
that looks like:
// Attach the servo to pin 10
var servo = new five.Servo(10);
Zgłoś jeśli naruszono regulamin