我使用的是:rpi-gpio (v2)
硬件:Raspberry Pi 3 b +
仅当我向GPIO pin 38
按下按钮时,我才发送高电平
我是一个名为server.js
的文件,其中包含我设置的pin_ins数组:
let pins = [38];
for (var i = =; i < pins.length; i++) {
gpio.setup(pins[i], gpio.DIR_IN, gpio.EDGE_BOTH);
}
之后,我使用on
更改事件侦听器:
gpio.on('change', function(pin, value) {
if(value) {
console.log('Pin:', pin, 'is set to', value);
}
});
当我使用以下脚本运行脚本时:sudo DEBUG=rpi-gpio node server.js
,我得到的结果是:
Channel 38 value is now false
rpi-gpio read pin 20 with value 0 +1ms
rpi-gpio emitting change on channel 38 with value false +1ms
Channel 38 value is now false
rpi-gpio read pin 20 with value 0 +1ms
rpi-gpio emitting change on channel 38 with value false +0ms
Channel 38 value is now false
rpi-gpio read pin 20 with value 0 +1ms
rpi-gpio emitting change on channel 38 with value false +1ms
Channel 38 value is now false
rpi-gpio read pin 20 with value 1 +1ms
rpi-gpio emitting change on channel 38 with value true +0ms
Channel 38 value is now true
rpi-gpio read pin 20 with value 1 +1ms
rpi-gpio emitting change on channel 38 with value true +0ms
Channel 38 value is now true
rpi-gpio read pin 20 with value 0 +1ms
rpi-gpio emitting change on channel 38 with value false +0ms
Channel 38 value is now false
rpi-gpio read pin 20 with value 1 +1ms
rpi-gpio emitting change on channel 38 with value true +0ms
Channel 38 value is now true
[....]
我在做什么错?