Last active
August 29, 2015 14:18
-
-
Save lynnaloo/0dcded35d28a91250172 to your computer and use it in GitHub Desktop.
Revisions
-
lynnaloo revised this gist
Apr 2, 2015 . 1 changed file with 22 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,20 +2,24 @@ var keypress = require("keypress"); var Spark = require("spark-io"); var five = require("johnny-five"); var Sumobot = require("sumobot")(five); var dotenv = require('dotenv'); // load the spark token and device id from .env file dotenv.load(); keypress(process.stdin); var board = new five.Board({ io: new Spark({ token: process.env.SPARK_TOKEN, deviceId: process.env.SPARK_DEVICE_ID }) }); board.on("ready", function() { console.log("Welcome to Sumobot Jr!"); // Initialize a new Sumobot. // - Left Servo is attached to pin D0 // - Right Servo is attached to pin D1 @@ -26,7 +30,7 @@ board.on("ready", function() { right: "D1", speed: 0.50 }); // Maps key names to bot methods var actions = { up: "fwd", @@ -35,30 +39,32 @@ board.on("ready", function() { right: "right", space: "stop" }; var mode; // Ensure the bot is stopped bot.stop(); // A bit of keypress ceremony ;) process.stdin.resume(); process.stdin.setEncoding("utf8"); process.stdin.setRawMode(true); process.stdin.on("keypress", function(ch, key) { var action; if (!key) { return; } action = actions[key.name] || key.name; if (action == "q") { console.log("Shutting down"); bot.stop(); setTimeout(process.exit, 500); } if (bot[action]) { if (mode === action) { return; -
lynnaloo created this gist
Mar 31, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ var keypress = require("keypress"); var Spark = require("spark-io"); var five = require("johnny-five"); var Sumobot = require("sumobot")(five); keypress(process.stdin); var board = new five.Board({ io: new Spark({ token: process.env.SPARK_TOKEN, deviceId: process.env.SPARK_DEVICE_2 }) }); board.on("ready", function() { console.log("Welcome to Sumobot Jr!"); // Initialize a new Sumobot. // - Left Servo is attached to pin D0 // - Right Servo is attached to pin D1 // - Speed set to 0.50 (half of max speed) // var bot = new Sumobot({ left: "D0", right: "D1", speed: 0.50 }); // Maps key names to bot methods var actions = { up: "fwd", down: "rev", left: "left", right: "right", space: "stop" }; // Ensure the bot is stopped bot.stop(); // A bit of keypress ceremony ;) process.stdin.resume(); process.stdin.setEncoding("utf8"); process.stdin.setRawMode(true); process.stdin.on("keypress", function(ch, key) { var action, mode; if (!key) { return; } action = actions[key.name] || key.name; if (action == "q") { console.log("Quitting"); bot.stop(); setTimeout(process.exit, 500); } if (bot[action]) { if (mode === action) { return; } bot[action](); mode = action; } }); });