IR remote repeat codes problem

Hi I have scraped this code together and it seemed to be working well.

The two buttons on the remote I have set up turn the outputs on for as long as I have the relevant button pressed and turn off the outputs when released Happy Days.

My problem is any other button apart from the two programmed cause problems and trigger the last output again as they all send the same repeat code.

I need to disable the repeat code to last good code conversion after some length of time has passed.

Hope someone can help

#include <IRremote.h>
#include <IRremoteInt.h> // This library does not need to be included at this point but it seems like it might be important?
long oldValue; // This value will save the last meaningful remote input and reuse it in the case of a repeat
int RECV_PIN = 12; // The pin that recieves the IR sensor Output. The leftmost pin when looking at the eye with pins down.
int volDelay = 100; //this value can be changed to move volume for longer increments

IRrecv irrecv(RECV_PIN); // The core IR parts of the program and the libraries come from Ken Shirriff's blog: A Multi-Protocol Infrared Remote Library for the Arduino
decode_results results;

void VolumePotOff()
{
  digitalWrite(4, LOW); // The core code for motor control came from http://www.hifivision.com/diy/44275-simple-ir-remote-motorized-alps-pot-directly-using-arduino.html
  digitalWrite(5, LOW);
}

void VolumeUp()
{
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
}
void VolumeDown()
{
  digitalWrite(4, LOW);
  digitalWrite(5, HIGH);
}

void setup()
{
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);

  VolumePotOff();
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  irrecv.blink13(true);
}


void loop()
{
  if (irrecv.decode(&results))
  {
    Serial.print(results.bits, DEC);
    Serial.print(" --results.value"); //printing newly recieved IR code to serial monitor
    Serial.print(results.value, HEX);
    irrecv.resume(); // Receive the next IR code. This code is an interrupt, so the arduino can go on with other tasks.

    if (results.value == 0x1FE40BF) //if up button pushed move motor forward with a 250ms shot of 5V
    {
      oldValue = results.value; //setting the placeholders value
      VolumeUp();
      delay(volDelay); //this value can be changed to move volume in bigger increments
      VolumePotOff();
    }

    else if (results.value == 0x1FEA05F) // down button pushed
    {
      oldValue = results.value;
      VolumeDown();
      delay(volDelay);
      VolumePotOff();
    }
    else if (results.value == 0xFFFFFFFF) // button is held down, do the last thing done, again
    {
      if (oldValue == 0x1FE40BF)
      {
        VolumeUp();
        delay(volDelay);
        VolumePotOff();
      }

      else if (oldValue == 0x1FEA05F)

      {
        VolumeDown();
        delay(volDelay);
        VolumePotOff();

      }
    }
    Serial.print(" --oldValue");
    Serial.println(oldValue, HEX); // this shows the placeholder at work and starts a new line in the serial monitor


  }
}

After the decode check if you have received the repeat code and if it's anything else then set oldvalue immediately. That way if the last code was an invalid code it will only be "repeating" a code that doesn't do anything.

Steve

Hi
Thank you for your reply.
I will try to work on implementing what you set out.
My brain is literally mush having spent the last few days on this.

Paul

HI

Thanks again been trying for ages, works now here is what I popped in with your help.

Ill get the hang of this stuff eventually

Paul

if(results.value != 0xFFFFFFFF)
oldValue = results.value;

#include <IRremote.h>
#include <IRremoteInt.h> // This library does not need to be included at this point but it seems like it might be important?
long oldValue; // This value will save the last meaningful remote input and reuse it in the case of a repeat
int RECV_PIN = 12; // The pin that recieves the IR sensor Output. The leftmost pin when looking at the eye with pins down.
int volDelay = 100; //this value can be changed to move volume for longer increments

IRrecv irrecv(RECV_PIN); // The core IR parts of the program and the libraries come from Ken Shirriff's blog: A Multi-Protocol Infrared Remote Library for the Arduino
decode_results results;

void VolumePotOff()
{
  digitalWrite(4, LOW); // The core code for motor control came from http://www.hifivision.com/diy/44275-simple-ir-remote-motorized-alps-pot-directly-using-arduino.html
  digitalWrite(5, LOW);
}

void VolumeUp()
{
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
}
void VolumeDown()
{
  digitalWrite(4, LOW);
  digitalWrite(5, HIGH);
}

void setup()
{
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);

  VolumePotOff();
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  irrecv.blink13(true);
}


void loop()
{
  if (irrecv.decode(&results))
 
  
  {
    Serial.print(results.bits, DEC);
    Serial.print(" --results.value"); //printing newly recieved IR code to serial monitor
    Serial.print(results.value, HEX);
    irrecv.resume(); // Receive the next IR code. This code is an interrupt, so the arduino can go on with other tasks.
     if(results.value != 0xFFFFFFFF)
     oldValue = results.value;

    if (results.value == 0x1FE40BF) //if up button pushed move motor forward with a 250ms shot of 5V
    {
      oldValue = results.value; //setting the placeholders value
      VolumeUp();
      delay(volDelay); //this value can be changed to move volume in bigger increments
      VolumePotOff();
    }

    else if (results.value == 0x1FEA05F) // down button pushed
    {
      oldValue = results.value;
      VolumeDown();
      delay(volDelay);
      VolumePotOff();
    }
    else if (results.value == 0xFFFFFFFF) // button is held down, do the last thing done, again
    {
      if (oldValue == 0x1FE40BF)
      {
        VolumeUp();
        delay(volDelay);
        VolumePotOff();
      }

      else if (oldValue == 0x1FEA05F)

      {
        VolumeDown();
        delay(volDelay);
        VolumePotOff();

      }
    }
    Serial.print(" --oldValue");
    Serial.println(oldValue, HEX); // this shows the placeholder at work and starts a new line in the serial monitor


  }
}