Created
May 16, 2014 21:58
-
-
Save makenai/6616049372c17a220fa4 to your computer and use it in GitHub Desktop.
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
var five = require("johnny-five"); | |
var Spark = require("spark-io"); | |
var keypress = require('keypress'); | |
var board = new five.Board({ | |
io: new Spark({ | |
token: "{YOURS}", | |
deviceId: "{YOURS}" | |
}) | |
}); | |
board.on("ready", function() { | |
console.log("Welcome to Sumobot Jr!") | |
console.log("Control the bot with the arrow keys, and SPACE to stop.") | |
var left_wheel = new five.Servo({ pin: "D5", type: "continuous" }).stop(); | |
var right_wheel = new five.Servo({ pin: "D6", type: "continuous" }).stop(); | |
var led = new five.Led("D7"); | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf8'); | |
process.stdin.setRawMode(true); | |
process.stdin.on('keypress', function (ch, key) { | |
if ( !key ) return; | |
if ( key.name == 'q' ) { | |
console.log('Quitting'); | |
process.exit(); | |
} else if ( key.name == 'up' ) { | |
console.log('Forward'); | |
left_wheel.ccw(); | |
right_wheel.cw(); | |
} else if ( key.name == 'l' ) { | |
led.on(); | |
} else if ( key.name == 'down' ) { | |
console.log('Backward'); | |
left_wheel.cw(); | |
right_wheel.ccw(); | |
} else if ( key.name == 'left' ) { | |
console.log('Left'); | |
left_wheel.ccw(); | |
right_wheel.ccw(); | |
} else if ( key.name == 'right' ) { | |
console.log('Right'); | |
left_wheel.cw(); | |
right_wheel.cw(); | |
} else if ( key.name == 'space' ) { | |
console.log('Stopping'); | |
left_wheel.stop(); | |
right_wheel.stop(); | |
led.off(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When/if you have a chance, can you try this: https://gist.github.com/rwaldron/0e34f40e65c60530ea14 with the latest version of Johnny-Five. Warning: I have literally not tested this code at all whatsoever ;)