IRremote - Trying to send multiple commands in loop()

I am trying to use the Due version of the IRremote library to send raw signals to a receiver. I want to send one signal, pause for some time and then send another. I have a header file set up with the different raw array values. I can successfully send a value to the receiver.

The issue is, when I attempt to send both signals from within the loop() function, it sends the first signal both times.

I don’t get this same issue if I send one in the setup() function and the other in the loop(). This works as expected, so I am fairly confident it is not an issue with the receiver.

I have tried changing the delay time in case it was due to that, but even with an extremely long delay, it makes no difference.

Can anyone offer some suggestions as to how I could do this?

Header File

unsigned int A_R_FWD[] = { 2800, 1150, 650, 400, 250, 800, 250, 800, 650, 400, 650, 400, 600, 400, 250, 850, 200, 850, 650, 400, 200, 850, 600, 400, 650, 400, 250, 800, 250, 800, 650, 400, 650 };

unsigned int A_R_BWD[] = { 2800, 1150, 250, 800, 250, 800, 300, 750, 650, 400, 650, 400, 650, 400, 200, 850, 250, 800, 250, 800, 250, 850, 650, 350, 650, 400, 250, 800, 250, 800, 650, 400, 650 };

unsigned int A_L_FWD[] = { 2800, 1150, 600, 450, 600, 400, 250, 850, 200, 850, 600, 450, 600, 400, 200, 850, 250, 850, 600, 400, 650, 400, 600, 450, 200, 850, 200, 850, 250, 850, 600, 400, 650 };

unsigned int A_L_BWD[] = { 2800, 1150, 650, 400, 200, 850, 650, 400, 200, 850, 650, 400, 650, 400, 250, 800, 300, 800, 600, 450, 600, 400, 250, 800, 300, 800, 250, 800, 250, 800, 600, 450, 600 };

unsigned int A_BOTH_FWD[] = { 2800, 1150, 650, 350, 250, 800, 250, 850, 250, 800, 650, 350, 650, 400, 250, 800, 250, 850, 650, 350, 250, 850, 600, 400, 250, 800, 250, 800, 250, 850, 650, 350, 650 };

unsigned int A_BOTH_BWD[] = { 2800, 1150, 650, 400, 650, 350, 650, 400, 250, 800, 650, 400, 650, 350, 250, 850, 200, 850, 250, 800, 250, 800, 250, 800, 250, 850, 200, 850, 250, 800, 650, 400, 600 };

unsigned int A_R_PIVOT[] = { 2800, 1150, 200, 850, 250, 800, 250, 800, 250, 850, 600, 400, 650, 400, 250, 800, 250, 800, 250, 850, 200, 850, 650, 400, 200, 850, 250, 800, 250, 800, 650, 400, 650 };

unsigned int A_L_PIVOT[] = { 2800, 1150, 200, 850, 650, 400, 650, 400, 200, 850, 650, 400, 600, 400, 250, 800, 250, 850, 600, 400, 250, 850, 200, 850, 250, 800, 250, 800, 250, 850, 650, 350, 650 };

Sketch code

/*
 * An IR LED must be connected to Arduino Due PWM pin 7.
*/


#include <IRremote2.h>
#include <tank.h>

int khz = 38; // 38kHz carrier frequency for the NEC protocol

void setup()
{
}

void loop() {

  goForward();

  delay(2000); 

  pivotRight();
}

void goForward(){
  IRsend irsend1;
  irsend1.sendRaw(A_BOTH_FWD, 33, khz);
}

void pivotRight(){
  IRsend irsend2;
  irsend2.sendRaw(A_R_PIVOT, 33, khz);
}

Put a delay after pivotRight. As you have it, immediately after you send it, loop is called again and immediately calls goForward again.

wildbill:
Put a delay after pivotRight. As you have it, immediately after you send it, loop is called again and immediately calls goForward again.

Thank you, that has sorted it. Not used to coding in a loop!