在 Node.js 中,我收到一条错误消息,指出我有一个意外的 setTimeout() 标识符。这是怎么回事?

In Node.js, I am getting an error saying that I have an unexpected identifier for setTimeout(). What's going on?

作为编程的初学者,我正在用 raspberry pi 做一个有趣的项目。我正在为带有节点模块的 raspberry pi 编写一个简单的程序,我想延迟 pi 的 GPIO 引脚打开和关闭(暂时)。我正在使用 set Timeout() 来延迟关闭 GPIO 引脚。 最大的问题是,当我 运行 我的文件时,我收到一条错误消息,指出 setTimeout() 是一个意外的标识符。有帮助吗?

关于我使用的节点模块的更多信息可以在这个link中找到:https://www.npmjs.com/package/pi-gpio

我的代码:

var gpio = require("pi-gpio");
var timers = require("timers"); //thought this might help fix problem
function start(){
    gpio.open(7, "output", function(err) {     // Open pin 7 for output 
    gpio.write(7, 1, function() {          // Set pin 7 high (1) 
        gpio.close(7);                     // Close pin 7 
    });
  });
}
function stop(){
    gpio.open(7, "output", function(err) {     // Open pin 7 for output 
    gpio.write(7, 0, function() {          // Set pin 7 low(0) 
       gpio.close(7);                     // Close pin 7 
   });
}
setTimeout(start,1000);
setTimeout(stop,3000);

这是我在 SSH 终端上得到的错误:

pi@raspberrypi ~ $ node armrobot.js
/home/pi/armrobot.js:16
setTimeout(start,1000);
^^^^^^^^^^
SyntaxError: Unexpected identifier
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

您没有正确关闭stop功能。

function stop(){
    gpio.open(7, "output", function(err) {     // Open pin 7 for output 
        gpio.write(7, 0, function() {          // Set pin 7 low(0) 
            gpio.close(7);                     // Close pin 7 
        });
    });
}