IR receiver only sees every second press of remote

Hi,
I've hijacked a program that works with the IR receiver, i wanted to try using a different remote control. It's working for every second press of the button, no matter how long i wait between pressing the button. Any idea why, code below. Thanks.

//www.elegoo.com
//2016.12.9

#include "IRremote.h"

int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 11

/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'

/*-----( Function )-----*/
void translateIR() // takes action based on IR code received
{
  int x = results.value;

  //I used the following line to find what the value the remote returned
  //Serial.println(x);   

  if(x == 262) {Serial.println("1");}
  if(x == 277) {Serial.println("2");}
  if(x == 285) {Serial.println("3");}
  if(x == 293) {Serial.println("4");}
  if(x == 270) {Serial.println("5");}
  if(x == 278) {Serial.println("6");}
  if(x == 286) {Serial.println("7");}
  if(x == 294) {Serial.println("8");}
  if(x == 263) {Serial.println("9");}
 
  delay(500); // Do not get immediate repeat
} 

void setup() 
{
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode"); 
  irrecv.enableIRIn(); // Start the receiver
}


void loop()  
{
  if (irrecv.decode(&results)) // have we received an IR signal?

  {
    translateIR(); 
    irrecv.resume(); // receive the next value
  }  
}

The program looks for specific values. Did you use Serial.println(x); to see what was being returned?

Paul

Your remote toggles a bit for each single key-press. This is to separate single press vs key held down.

use a mask (value && 255) to read only the lower 8 bits.

got it sorted, thanks lads