IR Library Using Case Switch

Hi,

I have this working sketch below. The apple remote uses the NEC protocol so if you continually hold down one of the remote
buttons, it will keep sending FFFFFFFF.

My question is how can I detect this continuous button press.

Since it's working for me in decimal, I will show it here. When I do the IR Receiver dump,

1st press displays
2011287691

1st press and hold displays
4294967295 (FFFFFFFF)

I tried doing something like this:

case 2011287691 or 4294967295:

That does not work though. No longer detects the remote button presses.

#include 

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
int led7 = 7;
int led8 = 8;

void setup()
{
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);

Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver

digitalWrite(led7, LOW);
digitalWrite(led8, LOW);

}

void loop() {
if (irrecv.decode(&results)) {
switch (results.value) {

case 2011287691: //UP
digitalWrite(led7, HIGH);
delay(500);
break;

case 2011279499:
digitalWrite(led8, HIGH);
delay(500);
break;

}
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
irrecv.resume(); // Receive the next value
}

Lynxo:
I tried doing something like this:

case 2011287691 or 4294967295:

That does not work though. No longer detects the remote button presses.

To do what you want, use:

case 2011287691:
case 4294967295:

Since there isn't a 'break;' statement between the two, both cases will do the same thing.

Thanks. It semi works but not correctly.

case 2011287691: //UP
case 4294967295:
digitalWrite(led7, HIGH);
delay(500);
break;

The problem is pressing the down key and holding, will it run the case for the UP key.

2nd problem, I can't use 2 case with same value, gives me duplicate value error.

Since I need both Up and Down keys, either could be pressed and held down which produces repeated F's.

There is a right way of doing this, I just don't know how.

The problem is pressing the down key and holding, will it run the case for the UP key.

You need three cases, obviously, AND you need to keep track of the last key pressed (the one before the repeat code appears) so you know what is being repeated.

delay(500);

Not a good idea...

PaulS:

The problem is pressing the down key and holding, will it run the case for the UP key.

You need three cases, obviously, AND you need to keep track of the last key pressed (the one before the repeat code appears) so you know what is being repeated.

I understand what you are saying but I don't know how to implement that.

delay(500);

Not a good idea...

why is the delay not a good idea? asking since I don't know why.

Would it make more sense to use the if and else if for this?

Does if statement run slower than switch case?

Would it make more sense to use the if and else if for this?

I think that, in this case, it would.

Does if statement run slower than switch case?

You could look at the resulting object code to answer that for yourself. You'd see that the resulting code is very similar, for a small number of cases. So, no, it isn't slower. After all, the correct block of code to execute still needs to be determined. Whether that decision is made using a switch statement and a bunch of cases, or a series of if/else if/else statements does not really matter.

why is the delay not a good idea? asking since I don't know why.

You won't be reading the remote during a delay(). If that matters...