Node.js Johnny five motors出现了一个奇怪的错误
我正试着让一个马达和约翰尼五号一起工作。我使用的是arduino,我从他们的网站上复制了代码和线路(大部分)。我在接线上唯一的改变是没有使用二极管来确保5V不会进入晶体管的发射极引脚,我只是将其直接连接到电机,而没有使用试验板。问题是,我犯了一个奇怪的错误 C:\Users\simas\node\u modules\johnny five\lib\motor.js:721 这是速度({ ^ TypeError:这不是一个函数 在Timeout.Motor.stop[as\u onTimeout](C:\Users\simas\node\u modules\johnny five\lib\Motor.js:721:8) 在ontimeout(timers.js:436:11) 在tryOnTimeout(timers.js:300:5) 在listOnTimeout(timers.js:263:5) at Timer.processTimers(timers.js:223:10) PS C:\Users\simas\Desktop\motors> 我一点也不明白为什么会发生这种情况,请帮忙 (顺便说一句,我从网站上复制的代码是:Node.js Johnny five motors出现了一个奇怪的错误,node.js,arduino,johnny-five,Node.js,Arduino,Johnny Five,我正试着让一个马达和约翰尼五号一起工作。我使用的是arduino,我从他们的网站上复制了代码和线路(大部分)。我在接线上唯一的改变是没有使用二极管来确保5V不会进入晶体管的发射极引脚,我只是将其直接连接到电机,而没有使用试验板。问题是,我犯了一个奇怪的错误 C:\Users\simas\node\u modules\johnny five\lib\motor.js:721 这是速度({ ^ TypeError:这不是一个函数 在Timeout.Motor.stop[as\u onTimeout]
const {Board, Motor} = require("johnny-five");
const board = new Board();
board.on("ready", () => {
// Create a new `motor` hardware instance.
const motor = new Motor({
pin: 5
});
// Inject the `motor` hardware into
// the Repl instance's context;
// allows direct command line access
board.repl.inject({
motor
});
// Motor Event API
// "start" events fire when the motor is started.
motor.on("start", () => {
console.log(`start: ${Date.now()}`);
// Demonstrate motor stop in 2 seconds
board.wait(2000, motor.stop);
});
// "stop" events fire when the motor is stopped.
motor.on("stop", () => {
console.log(`stop: ${Date.now()}`);
});
// Motor API
// start([speed)
// Start the motor. `isOn` property set to |true|
// Takes an optional parameter `speed` [0-255]
// to define the motor speed if a PWM Pin is
// used to connect the motor.
motor.start();
// stop()
// Stop the motor. `isOn` property set to |false|
});
)由于使用了,我也遇到了同样的问题 这似乎是绑定到
电机的上下文的问题。将函数直接传递到板时停止调用。等待
要解决此问题,请在motor实例上下文中声明您自己的函数,并将其传递给板。等待调用您的“start”
事件处理程序:
// "start" event fires when the motor is started
motor.on("start", () => {
console.log(`start: ${Date.now()}`);
// Demonstrate motor stop in 2 seconds
board.wait(2000, () => {
motor.stop();
});
});
由于使用了
这似乎是绑定到电机的上下文的问题。将函数直接传递到板时停止调用。等待
要解决此问题,请在motor实例上下文中声明您自己的函数,并将其传递给板。等待调用您的“start”
事件处理程序:
// "start" event fires when the motor is started
motor.on("start", () => {
console.log(`start: ${Date.now()}`);
// Demonstrate motor stop in 2 seconds
board.wait(2000, () => {
motor.stop();
});
});
示例似乎也是错误的。board.wait(5000,motor.stop)
应更改为board.wait(5000,()=>motor.stop())
。是的!不幸的是,许多(大多数)在线示例都遇到了同样的问题。示例似乎也是错误的。board.wait(5000,motor.stop)
应更改为board.wait(5000,()=>motor.stop())
.Yep!不幸的是,许多(大多数)在线示例都存在同样的问题。