Following along with the second half of Chapter Two of Kassandra Perchs’ book, Learning JavaScript Robotics, I learned how to control an LED in real time the Real-Eval-Print-Loop.

[all information below is paraphrased from Learning JavaScript Robotics, which is linked under Resources]

What is Read-Eval-Print-Loop?

Read-Eval-Print-Loop (REPL) allows you to modify the state of a robot, or its components, in real-time, or while the code is still running. REPL works because of Firmata – the board is just reacting to the node program, so if different instructions are sent through that program, the robot will react.

Using REPL to Control an LED

In order to make the components available to REPL, I used the line this.repl.inject().

this.repl allows you to access the REPL for the program you’re working on and inject accepts an object whose components you can access

By putting this into the program, it lets me have access to the LED through terminal using commands such as:

  • myLed.on()
  • myLed.off()
  • myLed.pulse()
  • myLed.strobe()
  • myLed.stop()
  • myLed.toggle()

LED Code with REPL and Schematics


Arduino MEGA board

LED Light