How to change delay upon recieving another input, Please Help! :~[SOLVED]

Hi,
In the below program, i want to change the delay (7th line from bottom) when i receive different commands from my ir remote control. For example when the recieved code is 0x801, the delay must be of 9ms, but when 0x802 is recieved, the delay must change to 7ms and so on.
Actually this delay decides the time at which a triac must be fired, so lesser the delay, higher the voltage across triac.
Any help would be appreciated, Thanks in Advance!

#include <IRremote.h>
int ledPin = 8; 
int inPin = 9;   
int val = 0;     
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin 13 as output
  pinMode(inPin, INPUT);      // sets the digital pin 7 as input
}
}

void loop()
{
  if(irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume();
  }
  {
    if(results.value == 0x801)
  digitalWrite(ledPin, HIGH);
  val = digitalRead(inPin);   // read the input pin
  if(val == HIGH)
  delay(9);
  digitalWrite(ledPin, LOW);    // sets the LED to the button's value
  if(val == HIGH)
  digitalWrite(ledPin, HIGH);
  else digitalWrite(ledPin, HIGH);
}
}

How about changing the line

  delay(9);

to

  delay (delayForCommand (results.value)) ;

and writing a function to convert command to delay value, something like:

unsigned long delayForCommand (int command)
{
  switch (command)
  {
  case 0x801:  return 9 ;
  case 0x801:  return 7 ;
  ...
  default:  return ... ;
  }
}

Thanks MarkT. It works!

Hi Everyone,
I am making a project to control bulb brightness and some led’s using ir remote. But when i try to control any of the led’s, the bulb brightness resets to default ( because of switch statement in the code). I also tried removing the default condition but it hangs the system when any other code is recieved from ir remote. There must be another way. I want the bulb brightness to change only when the assigned codes are recieved, else the bulb should remain at the same brightness irrespective of recieving any other code.
Seeking your help…
Here’s the code: (I am a noob so there may be some unnecessary mistakes in the code, regret)

#include <IRremote.h>
int SER_Pin = 6;   //pin 14 on the 75HC595
int RCLK_Pin = 5;  //pin 12 on the 75HC595
int SRCLK_Pin = 7; //pin 11 on the 75HC595
int ledPin = 8; // LED connected to digital pin 13
int inPin = 9;   // pushbutton connected to digital pin 7
int val = 0;     // variable to store the read value
int RECV_PIN = 11;
int led = 3;
//How many of the shift registers - change this
#define number_of_74hc595s 1 

//do not touch
#define numOfRegisterPins number_of_74hc595s * 8

boolean registers[numOfRegisterPins];
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin 13 as output
  pinMode(inPin, INPUT);      // sets the digital pin 7 as input
   pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);
  pinMode(led, OUTPUT);


  //reset all register pins
  clearRegisters();
  writeRegisters();
}
}

//set all register pins to LOW
void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
} 


//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}
void loop()
{
  if(irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume();
  }
     {
   if(results.value == 0x80C) digitalWrite(led, HIGH);
   if(results.value == 0xC) digitalWrite(led, HIGH);
   if(results.value == 0x80D) digitalWrite(led, LOW);
   if(results.value == 0xD) digitalWrite(led, LOW);

}
  {
  digitalWrite(ledPin, HIGH);
  val = digitalRead(inPin);   // read the input pin
  if(val == HIGH)
  delay (delayForCommand (results.value));
  digitalWrite(ledPin, LOW);    // sets the LED to the button's value
  if(val == HIGH)
  digitalWrite(ledPin, HIGH);
  }
  
  switch (results.value)
  
   {
       case 0x801:
  case 0x1:

  setRegisterPin(0, HIGH);
  setRegisterPin(1, LOW);
  setRegisterPin(2, LOW);
  setRegisterPin(3, HIGH);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, HIGH);
  setRegisterPin(7, HIGH);
   writeRegisters();
 
  }
   switch (results.value)
   {

   case 0x802:
   case 0x2:
   
  setRegisterPin(0, LOW);
  setRegisterPin(1, LOW);
  setRegisterPin(2, HIGH);
  setRegisterPin(3, LOW);
  setRegisterPin(4, LOW);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();
}
 switch (results.value)
{
case 0x803:
  case 0x3:

  setRegisterPin(0, LOW);
  setRegisterPin(1, LOW);
  setRegisterPin(2, LOW);
  setRegisterPin(3, LOW);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();
}

 switch (results.value)
{
case 0x804:
  case 0x4:

  setRegisterPin(0, HIGH);
  setRegisterPin(1, LOW);
  setRegisterPin(2, LOW);
  setRegisterPin(3, HIGH);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, LOW);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();
}

 switch (results.value)
{
case 0x805:
  case 0x5:

  setRegisterPin(0, LOW);
  setRegisterPin(1, HIGH);
  setRegisterPin(2, LOW);
  setRegisterPin(3, LOW);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, LOW);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();
}
switch (results.value)
{
case 0x800:
  case 0x0:

  setRegisterPin(0, HIGH);
  setRegisterPin(1, HIGH);
  setRegisterPin(2, HIGH);
  setRegisterPin(3, HIGH);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, HIGH);
  setRegisterPin(7, LOW);
   writeRegisters();
}
}

  
  unsigned long delayForCommand (int command)
  {
    switch (command)
    {
      case 0x800:
      case 0x0:
      return 9;
      case 0x801: 
      case 0x1:
      return 8;
      case 0x802:
      case 0x2:
      return 7;
      case 0x803:
      case 0x3:
      return 6;
      case 0x804:
      case 0x4:
      return 5;
      case 0x805:
      case 0x5:
      return 0;
      case 0x80C:
      case 0xC:
      return 9;
      default: return 9;
    }
  }

Please Help me guys!

What is the problem?

I want the bulb brightness to change only when the assigned codes are recieved, else the bulb should remain at the same brightness irrespective of recieving any other code.

So, write the code that way. You need to separate the logic of determining what the brightness level(s) should be from that of applying the level(s) to the pin(s). Only perform the logic of determining what the brightness level(s) should be when an IR command is received. Apply the levels every pass through loop, initially. Eventually, you should be able to determine when to apply the levels so you only do that once, too.

This code

   switch (results.value)
   {

   case 0x802:
   case 0x2:
   
  setRegisterPin(0, LOW);
  setRegisterPin(1, LOW);
  setRegisterPin(2, HIGH);
  setRegisterPin(3, LOW);
  setRegisterPin(4, LOW);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();
}
 switch (results.value)
{
case 0x803:
  case 0x3:

  setRegisterPin(0, LOW);
  setRegisterPin(1, LOW);
  setRegisterPin(2, LOW);
  setRegisterPin(3, LOW);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();
}

and so on makes me think that you have not fully taken on board the use of switch/case. It would be more normal to have one switch and many cases, not many pairs of switch/case each testing the value of the same variable

digitalWrite(ledPin, LOW);    // sets the LED to the button's valueNo it doesn't

How can i do that Paul, Please expand your statement.

The bulb continuously flashes if i make all the cases under one switch statement ( i dont know why ).

I suggest that you investigate why this happens. Which "bulb" are you talking about ? I imagine that it is an LED, but the variable names would seem to indicate that you have LEDs connected to pins 8 and 3, despiteint ledPin = 8; // LED connected to digital pin 13

Now please help me sort out the problem instead of highlighting my mistakes !

I am sorry if you are aggrieved that such erroneous comments are being pointed out but if you cannot get the comments right then to me it shows a lack of care and attention which may also be present in the code. As to highlighting your mistakes, surely that is what you want us to do in order to fix the problem.

Your attitude means that I will not be contributing further to this thread and your latest post has just hardened my resolve not to provide help.

There comes a time in every programming project where you start to think it might be time to re-factor.

I agree with UKHeliBob, your switch/case construct does not appear to be what you want.

Also, this:

  {
  digitalWrite(ledPin, HIGH);
  val = digitalRead(inPin);   // read the input pin
  if(val == HIGH)
  delay (delayForCommand (results.value));
  digitalWrite(ledPin, LOW);    // sets the LED to the button's value
  if(val == HIGH)
  digitalWrite(ledPin, HIGH);
  }

Could be written as:

digitalWrite(ledPin, HIGH);

val = digitalRead(inPin);

if(val == HIGH)
    {
    delay (delayForCommand (results.value));
    }

digitalWrite(ledPin, LOW); 

if(val == HIGH)
    {
    digitalWrite(ledPin, HIGH);
    }

Is that really how it should work? The addition of explicit curly braces {} around your 'if' blocks to makes it clearer which statements will and won't be run from it. Using an 'if' without curly braces is permissible when one and only one statement will be executed, but it is not recommended as it tends to lead to errors.

Also, you seem to use curly braces where they are not needed -- take those out, they are confusing. For example,

     { // this brace does nothing, remove it
   if(results.value == 0x80C) digitalWrite(led, HIGH);
   if(results.value == 0xC) digitalWrite(led, HIGH);
   if(results.value == 0x80D) digitalWrite(led, LOW);
   if(results.value == 0xD) digitalWrite(led, LOW);

} // this brace does nothing, remove it
  { // this brace does nothing, remove it
  digitalWrite(ledPin, HIGH);
  val = digitalRead(inPin);   // read the input pin
  if(val == HIGH)
  delay (delayForCommand (results.value));
  digitalWrite(ledPin, LOW);    // sets the LED to the button's value
  if(val == HIGH)
  digitalWrite(ledPin, HIGH);
  } // this brace does nothing, remove it

OK Tylernt, i removed those extranneous braces and added the necessary braces as you said. But the problem still exists, is there any way to sort out the problem ? I am stuck here since a long long time! Somebody please help me !

Hey! default must not return anything, that is the delay must remain as it is, it must not change in the default condition. Can the current delay value be stored and then recalled in the default state ? Thanks in advance !

default must not return anything,

You have to return something. You could pass the current value to the function, and return it only in the default case. Probably lots of other ways - pass the value by reference is another that springs to mind.

But the problem still exists

But you haven't posted your revised code.

Thanks for your reply Sir, Please guide me in more detail, Here is my code:

#include <IRremote.h>
int SER_Pin = 6;   //pin 14 on the 75HC595
int RCLK_Pin = 5;  //pin 12 on the 75HC595
int SRCLK_Pin = 7; //pin 11 on the 75HC595
int ledPin = 8; 
int inPin = 9; 
int val = 0; 
int RECV_PIN = 11;
int led = 3;
int led2 = 2;
//How many of the shift registers - change this
#define number_of_74hc595s 1 

//do not touch
#define numOfRegisterPins number_of_74hc595s * 8

boolean registers[numOfRegisterPins];
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();
{
  pinMode(ledPin, OUTPUT); 
  pinMode(inPin, INPUT); 
   pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);


  //reset all register pins
  clearRegisters();
  writeRegisters();
}
}

//set all register pins to LOW
void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
} 


//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}
void loop()
{
  if(irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume();
  }
     {
   if(results.value == 0x80C) digitalWrite(led, HIGH);
   if(results.value == 0xC) digitalWrite(led, HIGH);
   if(results.value == 0x80D) digitalWrite(led, LOW);
   if(results.value == 0xD) digitalWrite(led, LOW);

}
  {
  digitalWrite(ledPin, HIGH);
  val = digitalRead(inPin);   // read the input pin
  if(val == HIGH)
  delay (delayForCommand (results.value));
  digitalWrite(ledPin, LOW);    // sets the LED to the button's value
  if(val == HIGH)
  digitalWrite(ledPin, HIGH);
  }
  analogRead (delayForCommand (results.value));
  if ((delayForCommand (results.value)) == 8);
  digitalWrite (led2, HIGH);
  
  switch (results.value)
  
   {
       case 0x801:
  case 0x1:

  setRegisterPin(0, HIGH);
  setRegisterPin(1, LOW);
  setRegisterPin(2, LOW);
  setRegisterPin(3, HIGH);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, HIGH);
  setRegisterPin(7, HIGH);
   writeRegisters();

   case 0x802:
   case 0x2:
   
  setRegisterPin(0, LOW);
  setRegisterPin(1, LOW);
  setRegisterPin(2, HIGH);
  setRegisterPin(3, LOW);
  setRegisterPin(4, LOW);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();

case 0x803:
  case 0x3:

  setRegisterPin(0, LOW);
  setRegisterPin(1, LOW);
  setRegisterPin(2, LOW);
  setRegisterPin(3, LOW);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();

case 0x804:
  case 0x4:

  setRegisterPin(0, HIGH);
  setRegisterPin(1, LOW);
  setRegisterPin(2, LOW);
  setRegisterPin(3, HIGH);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, LOW);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();

case 0x805:
  case 0x5:

  setRegisterPin(0, LOW);
  setRegisterPin(1, HIGH);
  setRegisterPin(2, LOW);
  setRegisterPin(3, LOW);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, LOW);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();

case 0x800:
  case 0x0:

  setRegisterPin(0, HIGH);
  setRegisterPin(1, HIGH);
  setRegisterPin(2, HIGH);
  setRegisterPin(3, HIGH);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, HIGH);
  setRegisterPin(7, LOW);
   writeRegisters();
}
}

  
  unsigned long delayForCommand (int command)
  {
    switch (command)
    {
      case 0x800:
      case 0x0:
      return 9;
      case 0x801: 
      case 0x1:
      return 8;
      case 0x802:
      case 0x2:
      return 7;
      case 0x803:
      case 0x3:
      return 6;
      case 0x804:
      case 0x4:
      return 5;
      case 0x805:
      case 0x5:
      return 0;
      case 0x80C:
      case 0xC:
      return 9;
      default: [i][read the current value and return the same][/i] ;
    }
  }

Don’t cross-post please. Threads merged.

Thanks for your reply AWOL Sir, Please guide me how to do it. Here is my code:

#include <IRremote.h>
int SER_Pin = 6;   //pin 14 on the 75HC595
int RCLK_Pin = 5;  //pin 12 on the 75HC595
int SRCLK_Pin = 7; //pin 11 on the 75HC595
int ledPin = 8; 
int inPin = 9; 
int val = 0; 
int RECV_PIN = 11;
int led = 3;
int led2 = 2;
//How many of the shift registers - change this
#define number_of_74hc595s 1 

//do not touch
#define numOfRegisterPins number_of_74hc595s * 8

boolean registers[numOfRegisterPins];
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();
{
  pinMode(ledPin, OUTPUT); 
  pinMode(inPin, INPUT); 
   pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);


  //reset all register pins
  clearRegisters();
  writeRegisters();
}
}

//set all register pins to LOW
void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
} 


//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}
void loop()
{
  if(irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume();
  }
     {
   if(results.value == 0x80C) digitalWrite(led, HIGH);
   if(results.value == 0xC) digitalWrite(led, HIGH);
   if(results.value == 0x80D) digitalWrite(led, LOW);
   if(results.value == 0xD) digitalWrite(led, LOW);

}
  {
  digitalWrite(ledPin, HIGH);
  val = digitalRead(inPin);   // read the input pin
  if(val == HIGH)
  delay (delayForCommand (results.value));
  digitalWrite(ledPin, LOW);    // sets the LED to the button's value
  if(val == HIGH)
  digitalWrite(ledPin, HIGH);
  }
  analogRead (delayForCommand (results.value));
  if ((delayForCommand (results.value)) == 8);
  digitalWrite (led2, HIGH);
  
  switch (results.value)
  
   {
       case 0x801:
  case 0x1:

  setRegisterPin(0, HIGH);
  setRegisterPin(1, LOW);
  setRegisterPin(2, LOW);
  setRegisterPin(3, HIGH);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, HIGH);
  setRegisterPin(7, HIGH);
   writeRegisters();

   case 0x802:
   case 0x2:
   
  setRegisterPin(0, LOW);
  setRegisterPin(1, LOW);
  setRegisterPin(2, HIGH);
  setRegisterPin(3, LOW);
  setRegisterPin(4, LOW);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();

case 0x803:
  case 0x3:

  setRegisterPin(0, LOW);
  setRegisterPin(1, LOW);
  setRegisterPin(2, LOW);
  setRegisterPin(3, LOW);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();

case 0x804:
  case 0x4:

  setRegisterPin(0, HIGH);
  setRegisterPin(1, LOW);
  setRegisterPin(2, LOW);
  setRegisterPin(3, HIGH);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, LOW);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();

case 0x805:
  case 0x5:

  setRegisterPin(0, LOW);
  setRegisterPin(1, HIGH);
  setRegisterPin(2, LOW);
  setRegisterPin(3, LOW);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, LOW);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();

case 0x800:
  case 0x0:

  setRegisterPin(0, HIGH);
  setRegisterPin(1, HIGH);
  setRegisterPin(2, HIGH);
  setRegisterPin(3, HIGH);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, HIGH);
  setRegisterPin(7, LOW);
   writeRegisters();
}
}

  
  unsigned long delayForCommand (int command)
  {
    switch (command)
    {
      case 0x800:
      case 0x0:
      return 9;
      case 0x801: 
      case 0x1:
      return 8;
      case 0x802:
      case 0x2:
      return 7;
      case 0x803:
      case 0x3:
      return 6;
      case 0x804:
      case 0x4:
      return 5;
      case 0x805:
      case 0x5:
      return 0;
      case 0x80C:
      case 0xC:
      return 9;
      default: [i][read the current value and return the same][/i] ;
    }
  }

That's "Sir AWOL" to you. ;)

case 0x804:
  case 0x4:

  setRegisterPin(0, HIGH);
  setRegisterPin(1, LOW);
  setRegisterPin(2, LOW);
  setRegisterPin(3, HIGH);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, LOW);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();

case 0x805:
  case 0x5:

  setRegisterPin(0, LOW);
  setRegisterPin(1, HIGH);
  setRegisterPin(2, LOW);
  setRegisterPin(3, LOW);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, LOW);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();

Shouldn't there be some "break" statements there?

Try Googling how "switch" works.


     {
   if(results.value == 0x80C) digitalWrite(led, HIGH);
   if(results.value == 0xC) digitalWrite(led, HIGH);
   if(results.value == 0x80D) digitalWrite(led, LOW);
   if(results.value == 0xD) digitalWrite(led, LOW);

}

What are those extra braces for?

You forgot to put the above into code tags.

Better get a better web browser. Everyone else can.

Thanks for your reply Sir, Please guide me for it. Here is my code:

#include <IRremote.h>
int SER_Pin = 6;   //pin 14 on the 75HC595
int RCLK_Pin = 5;  //pin 12 on the 75HC595
int SRCLK_Pin = 7; //pin 11 on the 75HC595
int ledPin = 8; 
int inPin = 9; 
int val = 0; 
int RECV_PIN = 11;
int led = 3;
int led2 = 2;
//How many of the shift registers - change this
#define number_of_74hc595s 1 

//do not touch
#define numOfRegisterPins number_of_74hc595s * 8

boolean registers[numOfRegisterPins];
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();
{
  pinMode(ledPin, OUTPUT); 
  pinMode(inPin, INPUT); 
   pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);


  //reset all register pins
  clearRegisters();
  writeRegisters();
}
}

//set all register pins to LOW
void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
} 


//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}
void loop()
{
  if(irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume();
  }
     {
   if(results.value == 0x80C) digitalWrite(led, HIGH);
   if(results.value == 0xC) digitalWrite(led, HIGH);
   if(results.value == 0x80D) digitalWrite(led, LOW);
   if(results.value == 0xD) digitalWrite(led, LOW);

}
  {
  digitalWrite(ledPin, HIGH);
  val = digitalRead(inPin);   // read the input pin
  if(val == HIGH)
  delay (delayForCommand (results.value));
  digitalWrite(ledPin, LOW);    // sets the LED to the button's value
  if(val == HIGH)
  digitalWrite(ledPin, HIGH);
  }
  analogRead (delayForCommand (results.value));
  if ((delayForCommand (results.value)) == 8);
  digitalWrite (led2, HIGH);
  
  switch (results.value)
  
   {
       case 0x801:
  case 0x1:

  setRegisterPin(0, HIGH);
  setRegisterPin(1, LOW);
  setRegisterPin(2, LOW);
  setRegisterPin(3, HIGH);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, HIGH);
  setRegisterPin(7, HIGH);
   writeRegisters();
 break;
   case 0x802:
   case 0x2:
   
  setRegisterPin(0, LOW);
  setRegisterPin(1, LOW);
  setRegisterPin(2, HIGH);
  setRegisterPin(3, LOW);
  setRegisterPin(4, LOW);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();
 break;
case 0x803:
  case 0x3:

  setRegisterPin(0, LOW);
  setRegisterPin(1, LOW);
  setRegisterPin(2, LOW);
  setRegisterPin(3, LOW);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();
 break;
case 0x804:
  case 0x4:

  setRegisterPin(0, HIGH);
  setRegisterPin(1, LOW);
  setRegisterPin(2, LOW);
  setRegisterPin(3, HIGH);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, LOW);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();
 break;
case 0x805:
  case 0x5:

  setRegisterPin(0, LOW);
  setRegisterPin(1, HIGH);
  setRegisterPin(2, LOW);
  setRegisterPin(3, LOW);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, LOW);
  setRegisterPin(6, LOW);
  setRegisterPin(7, HIGH);
   writeRegisters();
 break;
case 0x800:
  case 0x0:

  setRegisterPin(0, HIGH);
  setRegisterPin(1, HIGH);
  setRegisterPin(2, HIGH);
  setRegisterPin(3, HIGH);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, HIGH);
  setRegisterPin(7, LOW);
   writeRegisters();
    break;
}
}

  
  unsigned long delayForCommand (int command)
  {
    switch (command)
    {
      case 0x800:
      case 0x0:
      return 9;
      case 0x801: 
      case 0x1:
      return 8;
      case 0x802:
      case 0x2:
      return 7;
      case 0x803:
      case 0x3:
      return 6;
      case 0x804:
      case 0x4:
      return 5;
      case 0x805:
      case 0x5:
      return 0;
      case 0x80C:
      case 0xC:
      return 9;
      default: [i][read the current value and return the same][/i] ;
    }
  }