Last active
July 14, 2019 00:44
-
-
Save phoddie/17601031d83602f688c20c98292c622e to your computer and use it in GitHub Desktop.
etherport option for firmata.js repl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const firmata = require("./lib/firmata"); | |
const Etherport = require("Etherport"); | |
const repl = require("repl"); | |
console.log('Enter USB Port or "etherport" and press enter:'); | |
process.stdin.resume(); | |
process.stdin.setEncoding("utf8"); | |
process.stdin.once("data", (chunk) => { | |
chunk = chunk.replace("\n", ""); | |
const port = ("etherport" === chunk) ? new Etherport(3030) : chunk.replace("\n", ""); | |
const board = new firmata.Board(port, () => { | |
console.log(`Successfully Connected to ${port}`); | |
repl.start("firmata>").context.board = board; | |
}); | |
board.on("string", msg => console.log(`Board message: ${msg}`)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment