我有一个代码,不是我写的,控制机器人手臂的跳跃运动和arduino。利用强尼五和跳跃。我试过了,它起作用了,就像我移动手的方式--机器人的手臂在动。没问题。但我想用键盘移动。就像我按下一个特定的键--一个伺服旋转键--只要我按住这个键等等,总共有四个伺服,每个都有自己的键盘键,
例如(伺服1按"a“表示左边,"b”表示右边。伺服2“z”为左,c为右)
我真的没有编写使用跃变运动的原始代码,但是我让它运行它,它适用于所有的伺服系统。现在我想把它变成键盘控制。有人能帮忙吗?我不知道用键盘控制机器人手臂(4伺服)的代码
发布于 2015-02-19 16:15:30
我推荐keypress模块:
var five = require("johnny-five");
var keypress = require("keypress");
// Set up keypress
keypress(process.stdin);
// Initialize a new Board object
var board = new five.Board();
board.on("ready", function() {
// Create two servos, on pins 9 and 10
var servo1 = new five.Servo(9);
var servo2 = new five.Servo(10);
// Set up stdin to work correctly with the REPL
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.setRawMode(true);
// When keys are pressed...
process.stdin.on("keypress", function(ch, key) {
if (!key) {
return;
}
if (key.name === "a") {
// Change 0 to whatever degree is "left"
servo1.to(0);
}
if (key.name === "b") {
// Change 0 to whatever degree is "right"
servo1.to(0);
}
if (key.name === "z") {
// Change 0 to whatever degree is "left"
servo1.to(0);
}
if (key.name === "c") {
// Change 0 to whatever degree is "right"
servo1.to(0);
}
});
});https://stackoverflow.com/questions/28584804
复制相似问题