Capturing multiple IR Codes

Posted on
  • hi everyone,

    Does any know how to capture multiple IR codes through an IR receiver at the same time? My remote seems to send multiple codes on a single press. How do you capture them on times?

    This example is good to capture events one code at a time. I can print them to console using
    console.log(times.toString());

    but the problem is it is always printing the last one received.

    digitalWrite(B7, 0); // Set B7 to GND
    digitalWrite(A8, 1); // Set A8 to 3.3V
    // Because we're not using the module, we have to manually pull up the data pin
    pinMode(B6,"input_pullup");
    // Keep somewhere to put the signal times
    var times = [];
    // now watch the input
    setWatch(function(e) {
      // work out how long the pulse was, in milliseconds
      var pulseLen = 1000 * (e.time - e.lastTime);
      // then save it, if it was less than 1 second
      if (pulseLen < 1000)
        times.push(pulseLen);
      else
        times = [];
    }, B6, {repeat:true});
    

    Thanks
    Navas

  • Sure, probably the easiest way is to just store the times in a second array. Try something like this:

    digitalWrite(B7, 0); // Set B7 to GND
    digitalWrite(A8, 1); // Set A8 to 3.3V
    // Because we're not using the module, we have to manually pull up the data pin
    pinMode(B6,"input_pullup");
    // Keep somewhere to put the signal times
    var times = [];
    var history = [];
    // now watch the input
    setWatch(function(e) {
      // work out how long the pulse was, in milliseconds
      var pulseLen = 1000 * (e.time - e.lastTime);
      // then save it, if it was less than 1 second
      if (pulseLen < 1000)
        times.push(pulseLen);
      else {
       history.push(new Float32Array(times));
        times = [];
      }
    }, B6, {repeat:true});
    

    That'll stick everything in history - it uses Float32Array to make sure it can fit a lot of IR recordings in if you need it.

    It's worth checking though - most IR remotes just repeat the same pattern over and over (rather than different ones)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Capturing multiple IR Codes

Posted by Avatar for navas @navas

Actions