I have a probably very simple question. I have a Raspberry Pi 3 model B+ running Raspbian Buster hooked up to an infrared receiver on GPIO 7 (pin 26) and an LED hooked up to GPIO 4 (pin 7). What I want to do is to switch on the LED as soon as the receiver receives an infrared signal and back off again if it receives receives the signal again. This is running as a Node.js Script. It is important to mention that the infrared signal should be random and shouldn't be decoded. Any signal should do the job. In order to read the IR input on GPIO 7, I am using the rpi-gpio packet. But when I fire an IR signal from a remote, the LED turns on and off in a high frequency (I'm guessing in the frequency of the IR signal bursts). So what I want to do is for the LED to only react to the very first input change on the GPIO pin and not to react to all of the changes provoked by the IR signal code. The simple code I have so far is as follows:
//used for IR receiver, refers to pins as pin#
var gpio = require('rpi-gpio');
//used for LED, refers to pins as GPIO#
var Gpio = require('onoff').Gpio;
var LED = new Gpio(4, 'out');
//listening for GPIO input changes
gpio.on('change', function(channel, value) {
console.log('Channel ' + channel + ' value is now ' + value);
blinkLED();
});
gpio.setup(26, gpio.DIR_IN, gpio.EDGE_BOTH);
//changing state of LED
function blinkLED() {
if (LED.readSync() === 0) {
LED.writeSync(1);
} else {
LED.writeSync(0);
}
}
Does anyone have any ideas? Is it maybe possible to stop listening for inputs after the first change? How would I do that? I'm grateful for any help and hints! enjoy your weekend!