Rover 5 Infrared Code Processing Notes

ATmega328 Programming to Capture Infrared Codes

Here is an excerpt of my program that records Infrared Codes, based on this Tutorial, with a few enhancements added:

    // Capture the duration of the Long or Short pulse.
    //
    while (IRpin_PORT & bit( IRpin))
    {
      // Pin is still HIGH.
      // count off another few microseconds.
      //
      onPulseDuration++;
      delayMicroseconds( RESOLUTION);

      // If the pulse is too long, we 'timed out' - either nothing
      // was received or the code is finished, so print what
      // we've grabbed so far, and then reset
      //
      if (onPulseDuration >= MAXPULSEDURATION && numPulsesReceived != 0)
       return numPulsesReceived;
    }
    receivedPulses[numPulsesReceived][0] = onPulseDuration;

    // Same as above, this time for the Off pulse.
    //
    while (!(IRpin_PORT & _BV( IRpin)))
    {
      // Pin is still LOW.
      //
      offPulseDuration++;
      delayMicroseconds( RESOLUTION);

      if (offPulseDuration >= MAXPULSEDURATION && numPulsesReceived != 0)
       return numPulsesReceived;
    }
    receivedPulses[numPulsesReceived][1] = offPulseDuration;

    // We read one (Long or Short) and Off pulse successfully, so continue!
    //
    numPulsesReceived++;

Back to Previous Page...