O'Reilly logo

Learning JavaScript Robotics by Kassandra Perch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 up our button and LED

Wiring diagram for a button and an LED

Make sure that if you're using the four-prong ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required