Created
July 25, 2015 14:38
-
-
Save robtarr/07591ebdce30821171bf to your computer and use it in GitHub Desktop.
Simple Johnny-Five demo
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"), | |
keypress = require('keypress'), | |
board = new five.Board(), | |
stdin = process.stdin; | |
keypress(process.stdin); | |
stdin.setRawMode(true); | |
stdin.resume(); | |
board.on("ready", function() { | |
// Johnny-Five provides pre-packages shield configurations! | |
// http://johnny-five.io/api/motor/#pre-packaged-shield-configs | |
var motors = new five.Motors([ | |
five.Motor.SHIELD_CONFIGS.POLOLU_DRV8835_SHIELD.M1, | |
five.Motor.SHIELD_CONFIGS.POLOLU_DRV8835_SHIELD.M2, | |
]), | |
leftMotor = motors[0], | |
rightMotor = motors[1]; | |
console.log('Ready!'); | |
stdin.on("keypress", function (chunk, key) { | |
if (!key) return; | |
if (key.ctrl && key.name == 'c' || key.name == 'q') { | |
process.exit(); | |
} | |
switch(key.name) { | |
case "up": | |
motors.fwd(255); | |
break; | |
case "down": | |
motors.rev(255); | |
break; | |
case "space": | |
motors.stop(); | |
break; | |
case "right": | |
motors[1].fwd(75); | |
motors[0].rev(75); | |
break; | |
case "left": | |
motors[0].fwd(75); | |
motors[1].rev(75); | |
break; | |
default: | |
break; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment