Book Image

Learning JavaScript Robotics

By : Kassandra Perch
Book Image

Learning JavaScript Robotics

By: Kassandra Perch

Overview of this book

Table of Contents (16 chapters)
Learning JavaScript Robotics
About the Author
About the Reviewers

Multiple pins with several LEDs

For the next project, we're going to look at the Led object API and test several different methods. This is one of the benefits of Johnny-Five—abstraction. If you can understand the concept of an LED, you can use the Johnny-Five LED object without thinking about the underlying pins or timings. Let's go over the methods that we'll use for our project:

  • on() and off(): These turn an LED on and off. Under abstraction, this sets the pin that is wired to the LED to HIGH and LOW, respectively. We'll be using these in the REPL.

  • blink(time): This turns an LED on and off at a given interval. strobe() and blink() are aliases of each other and do the same thing.

  • pulse(time): This will cause an LED to pulse on and off in an eased manner. This requires an LED wired to a PWM pin. The time argument sets the length of each side of the pulse—500 will mean the LED will fade in for 500 ms and fade out for 500 ms, meaning a 1-second pulse.

  • fade(brightness, ms): This will cause...