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
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using the Read-Eval-Print-Loop (REPL)


The Read, Eval, Print Loop, or REPL, is a concept relative to many scripting languages, but it is new to libraries, and definitely new to robotics. Think about how you alter the state in a typical Arduino program: you modify the source code, re-load it onto the board, and wait for it to run.

However, due to the way Johnny-Five works, we can modify the state of our robot code while the code is running. This is because we use Firmata—the board is just a thin client that reacts to instructions from our node program, so if we let our Node programs send different instructions, we can change how our robot works in real time.

The way to do this in a Johnny-Five program is by injecting components into the REPL, which allows us to use them.

Making components available to the REPL

We're going to modify our script from the previous section in order to manipulate our LED. To do this, we're going to use the this.repl.inject() function. The this keyword, when used within...