Single IR Code to flip between two outputs

I have an unusual project. I'm using a device only capable of transmitting one code over IR. All attempts get it firing more than one have been unsuccessful, which is a problem because i need to have it both push and pull an actuator. However, the receiver side may be my way in. It's a simple motor driver board connected to a UNO.

So my goal is to have this receiver take the single code and do one thing, then on the second press, the other.

Here's the code. Note: its for a multi button remote. Trying to modify it to work with one.

#include <IRremote.h>
#define irPin 3

IRrecv irrecv(irPin);
decode_results results;
#define in1 5
#define in2 6

const int buzzer = 9;
#define buzzer 9
void setup() 
{
    Serial.begin(9600);
    irrecv.enableIRIn();
    
    pinMode(in1, OUTPUT); 
    pinMode(in2, OUTPUT);
    pinMode(buzzer, OUTPUT); // Unused buzzer
}
void loop()
{
   if (irrecv.decode(&results)) 
   {
    Serial.print(results.value, HEX);
    Serial.print(" - ");
    Serial.println(results.value);
      switch (results.value) 
      {
            case 50161: //Actuator PULL
            digitalWrite(in1,HIGH);
            delay(500);
            digitalWrite(in1,LOW);
            delay(250);
            break;
            case 50174: //Actuator PUSH
            digitalWrite(in2,HIGH);
            delay(500);
            digitalWrite(in2,LOW);
            delay(250);
            break;  
            
           }
            
   irrecv.resume();
   }
}

This isn't my code btw. I just hacked it a little.Preformatted text

Does the transmitter send just one code burst per press, or a stream as long as the key is pressed?

Please remember to use code tags when posting code

Why?
Don't you trust the compiler?

Arduino forums noob. Will add code tags.

Also was trying everything to get something to work earlier so that's left over junk code.

Oh and it sends one code.

#include <IRremote.h>
#define irPin 3

IRrecv irrecv ( irPin );
decode_results results;
#define in1 5
#define in2 6

boolean pulled = true; // initial state of actuator

void setup ()
{
  Serial.begin ( 115200 );
  irrecv.enableIRIn ();
  pinMode ( in1, OUTPUT );
  pinMode ( in2, OUTPUT );
  
  // Actuator PULL initial state
  digitalWrite ( in1, HIGH );
  delay ( 500 );
  digitalWrite ( in1, LOW );
  delay ( 250 );
}

void loop ()
{
  if ( irrecv.decode ( &results ) )
  {
    Serial.print ( results.value, HEX );
    Serial.print ( " - " );
    Serial.println ( results.value );
    
    if ( results.value == 50505 ) // theOne IR code
    {
      if ( pulled )
      {
        // Actuator PUSH
        digitalWrite ( in2, HIGH );
        delay ( 500 );
        digitalWrite ( in2, LOW );
        delay ( 250 );
        pulled = false;
      }
      else
      {
        // Actuator PULL
        digitalWrite ( in1, HIGH );
        delay ( 500 );
        digitalWrite ( in1, LOW );
        delay ( 250 );
        pulled = true;
      }
    }
    irrecv.resume ();
  }
}
1 Like