Disable a Remote Control button after it's pressed

Hello everyone,

I will use a stepper motor for a curtain, so when the motor opens the curtain by pressing button 1, I want that button to be disabled because if I press it again, it will rotate again in the same way and will break my things.
Button 1- Open the curtain by rotating right -> Disable Button 1 -> Enable Button 2.
Button 2- Close the curtain by rotating left -> Disable Button 2 -> Enable Button 1

My code:

void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
switch(results.value)
{
case Button1: // Right button pressed
//Motor CODE
break;

case Button2: // Left button pressed
//Motor CODE
break;

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


I hope someone could help me, thanks!

If I understand your question correctly, you just neeed to set a flag for each button. for example:

      case Button1: // Right button pressed
                     if (rightButtonPressed == false)
                       {
                           rightButtonPressed = true;
                          //Motor CODE
                       }
                      leftButtonPressed = false;
                      break;

Sorry but I don’t get that. What rightButtonPressed and leftButtonPressed should be?

In my code, Button1 = 0xFF6897 and Button2= 0xFF30CF. I need somehow to disable case 0xFF6897 after it’s pressed, enabling 2nd case option, and by pressing 2nd vice versa.

You just need to declare two new (global) variables at the start of your program:

  byte rightButtonPressed = false;
  byte leftButtonPressed = false;

setup() {
.....
}

It worked, thanks a lot quilkin, great brain you got there :smiley:
Now I have to think how to store this after I unplug the power, because it resets.

Hit the correct button because the variables are declared at the start so you can start on any option.