Johnny Five, how to use a REPL

This post is part of the Johnny Five series. See the first post here.

When you run a program using Johnny Five, you can see that in the terminal, we have access to a REPL, a term that means Read-Evaluate-Print-Loop.

In other words, we ca…


This content originally appeared on flaviocopes.com and was authored by flaviocopes.com

This post is part of the Johnny Five series. See the first post here.

When you run a program using Johnny Five, you can see that in the terminal, we have access to a REPL, a term that means Read-Evaluate-Print-Loop.

In other words, we can write commands in here.

Let’s try by creating a repl.js file with this code:

const { Board } = require("johnny-five")
const board = new Board()

I am going to play with the LCD circuit made in the previous lesson.

Run the program with node repl.js:

Next, we’re going to write some commands in the REPL.

Start by requiring the LCD class:

const { LCD } = require("johnny-five")

Then initialize an lcd object from it:

const lcd = new LCD({ pins: [7, 8, 9, 10, 11, 12] })

Now write to the LCD display:

lcd.print("Hello!")

You’ll see a big message coming back:

Because the command returns a reference to the LCD object. This is to let us chain commands together, like this:

lcd.clear().print("Hello!")

If you don’t run clear(), any new thing you write is going to be appended to the one already there.

To write to the second row, you call cursor(1) (the default row is 0:

lcd.clear().print("Hello from")
lcd.cursor(1, 0).print("Johnny-Five!")


This content originally appeared on flaviocopes.com and was authored by flaviocopes.com


Print Share Comment Cite Upload Translate Updates
APA

flaviocopes.com | Sciencx (2021-04-29T05:00:00+00:00) Johnny Five, how to use a REPL. Retrieved from https://www.scien.cx/2021/04/29/johnny-five-how-to-use-a-repl/

MLA
" » Johnny Five, how to use a REPL." flaviocopes.com | Sciencx - Thursday April 29, 2021, https://www.scien.cx/2021/04/29/johnny-five-how-to-use-a-repl/
HARVARD
flaviocopes.com | Sciencx Thursday April 29, 2021 » Johnny Five, how to use a REPL., viewed ,<https://www.scien.cx/2021/04/29/johnny-five-how-to-use-a-repl/>
VANCOUVER
flaviocopes.com | Sciencx - » Johnny Five, how to use a REPL. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/29/johnny-five-how-to-use-a-repl/
CHICAGO
" » Johnny Five, how to use a REPL." flaviocopes.com | Sciencx - Accessed . https://www.scien.cx/2021/04/29/johnny-five-how-to-use-a-repl/
IEEE
" » Johnny Five, how to use a REPL." flaviocopes.com | Sciencx [Online]. Available: https://www.scien.cx/2021/04/29/johnny-five-how-to-use-a-repl/. [Accessed: ]
rf:citation
» Johnny Five, how to use a REPL | flaviocopes.com | Sciencx | https://www.scien.cx/2021/04/29/johnny-five-how-to-use-a-repl/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.