Created
July 3, 2017 14:10
-
-
Save ghtomcat/71e512ecc00d147caafc2dda15af07e1 to your computer and use it in GitHub Desktop.
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 characters
var keypress = require('keypress'); | |
var five = require("johnny-five"); | |
var EtherPortClient = require("etherport-client").EtherPortClient; | |
var board = new five.Board({ | |
port: new EtherPortClient({ | |
host: "xx.xx.xx.xx", | |
port: 3030 | |
}), | |
timeout: 1e5, | |
repl: false | |
}); | |
board.on("ready", function() { | |
console.log("READY!"); | |
var leftWheel= new five.Motor({ | |
pins: { | |
pwm: 15, | |
dir: 13 | |
} | |
}); | |
var rightWheel = new five.Motor({ | |
pins: { | |
pwm: 14, | |
dir: 12 | |
} | |
}); | |
leftWheel.setPWM(15,0); | |
leftWheel.setPin(13,0); | |
rightWheel.setPWM(14,0); | |
rightWheel.setPin(12,0); | |
keypress(process.stdin); | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf8'); | |
process.stdin.setRawMode(true); | |
console.log("press a key"); | |
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'); | |
leftWheel.setPWM(15,2000); | |
leftWheel.setPin(13,0); | |
rightWheel.setPWM(14,2000); | |
rightWheel.setPin(12,0); | |
} else if ( key.name === 'down' ) { | |
console.log('Backward'); | |
leftWheel.setPWM(15,0); | |
leftWheel.setPin(13,1) | |
rightWheel.setPWM(14,0); | |
rightWheel.setPin(12,1); | |
} else if ( key.name === 'space' ) { | |
console.log('Stopping'); | |
leftWheel.setPin(13,0); | |
leftWheel.setPWM(15,0); | |
rightWheel.setPin(12,0); | |
rightWheel.setPWM(14,0); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment