Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning JavaScript Robotics

You're reading from  Learning JavaScript Robotics

Product type Book
Published in Nov 2015
Publisher
ISBN-13 9781785883347
Pages 160 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Kassandra Perch Kassandra Perch
Profile icon Kassandra Perch

Table of Contents (16) Chapters

Learning JavaScript Robotics
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Getting Started with JS Robotics Working with Johnny-Five Using Digital and PWM Output Pins Using Specialized Output Devices Using Input Devices and Sensors Moving Your Bot Advanced Movement with the Animation Library Advanced Components – SPI, I2C, and Other Devices Connecting NodeBots to the World, and Where to Go Next Index

Using basic inputs – buttons and potentiometers


Let's take a look at using some basic input devices first. We'll start with a button and a potentiometer—two of the easiest input devices to use with Johnny-Five, and a good way to get acquainted with both specialized input objects, such as buttons, and general Sensor objects, which we'll use for the potentiometer.

Wiring up our button and LED

First, we're going to wire up a button and write some code to measure whether it is pressed or not, using an LED as our indicator. The wiring of the project will look like this:

Wiring diagram for a button and an LED

Make sure that if you're using the four-prong button, it crosses over the center trough of your breadboard as shown in the diagram. If it does not, the button will not work properly. If you are using a two-prong button, the wiring is very similar, and it does not have to cross over.

Coding button-led.js

Now, let's take a look at the Button object in Johnny-Five to see what we'll need to use for...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}