IR Led On/Off

Hi,

So im trying to use an IR Remote to control LED's through an Arduino Uno. I've gotten it to the point where I have a "Power" Led that is tied to the power button on the remote. When it's pressed, if its off, it turn on, if its on, it turns off. I have 2 other LED's tied to 1 and 2 on the remote. When I press the power button, I have it so all LED's shut off. My issue is, after I reset it when I turn on the power, and press 1 and 2 they come on with 1 click as should. If I shut them all off through only hitting the power button, when I press the power again they stay off as should. But, when I go to turn 1 and 2 on it takes 2 clicks each on the remote to get them to turn on. I've been looking at this for hours and can't find what is the issue. Does anyone have any insight on at least what I should look into to figure this out? Or does anyone see obvious issues in this code? ONLED is the power, and convfwled and convrvled are the other ones, tied to 1 and 2 on the remote respectively. Thank you!

#include "IRremote.h"

int receiver = 11; //Declares signal pin of IR reciever
int ONLED = 8; //declares system on pin
int convfwled = 12; //declares conveyor forward pin
int convrvled = 10; //declares conveyor reverse pin
int systemOn = {0,0,0,0}; //set system to off(zero)
#define Oncode 0xFFA25D //defines ir power button as Oncode
#define convfwcode 0xFF30CF //defines conveyor forward code for button 1
#define convrvcode 0xFF18E7 //defines conveyor reverse code for button 2

IRrecv irrecv(receiver); //creates instance of reciever
decode_results results; //creates instance of decode results

void translateIR() //translates IR in to perform an action

{
switch(results.value)

{

case Oncode: //action for Oncode/power button depressed

if(systemOn[1] == 1) { //if system is on

Serial.println("Power"); //Prints power button depressed
digitalWrite(ONLED, LOW); //turn off when power button pressed
systemOn[1] = 0; //sets state of system as off
digitalWrite(convfwled, LOW); //sets conveyor forward to off
digitalWrite(convrvled, LOW); //sets conveyor reverse to off

}
else
{ //else if system is off
digitalWrite(ONLED, HIGH); //turn system on when button is pressed
systemOn[1] = 1; //sets system state to on
}
break;
case convfwcode:
if(systemOn[1] == 1) { //if system 1 is on
if(systemOn[2] == 1) { //if system 2 is on (1 depressed)
digitalWrite(convfwled, LOW); //turn off when 1 button is depressed
systemOn[2] = 0; //set system 2 to off
}
else //else if system 2 is off
{
digitalWrite(convfwled, HIGH); //turn system on when 1 is depressed
systemOn[2] = 1; //set system state to on
}
}
break;
case convrvcode:
if(systemOn[1] == 1) { //if system 1 is on
if(systemOn[3] == 1) { //if system 3 is on (1 depressed)
digitalWrite(convrvled, LOW); //turn off when 2 button is depressed
systemOn[3] = 0; //set system 3 to off
}
else //else if system 2 is off
{
digitalWrite(convrvled, HIGH); //turn system on when 2 is depressed
systemOn[3] = 1; //set system state to on
}
}

default:
Serial.println("Other Button"); //Prints button is not specified

}
delay(500); //Prevents immediate repeat

}

void setup() {
Serial.begin(9600); //setting up monitor frequency
Serial.println("IR Receiver Button Decode");
irrecv.enableIRIn(); //Start the reciever
pinMode(ONLED, OUTPUT); //sets onled to an output
pinMode(convfwled, OUTPUT); //sets conveyor forward led to output
pinMode(convrvled, OUTPUT); //sets conveyor reverse led to output

}

void loop() {

if (irrecv.decode(&results)) //Checks to see if IR signal recieved

{
translateIR(); //runs translate if signal received
irrecv.resume(); //resumes sequence, ready for next value
}
}

I know this is a bad image so:

Blue LED on left power is from pin 8, grounded to that side ground as well
Green LED in middle power is from pin 12, grounded to that side ground
Red LED on right power is from pin 10, grounded
IR has black lead to ground, red lead to 5v, yellow lead to pin 11

I don't have link to components as they're from an elegoo kit, but it is an elegoo Arduino uno with the prototype shield on it, elegoo ir receiver and ir remote

Please show us a good schematic of your circuit.
Show us a good image of your wiring.
Give links to components.
Posting images:

Would you repost your code one more time, first format it with or .

BTW, arrays start at zero i.e. systemOn[0] first element.

I'll get an image in a moment, but tagging the code like that doesn't seem to be doing anything, tried both CMD and CTRL

I think it's because you are not marking the LEDs as off in the array on power down, so the program thinks they are still on.

    if(systemOn[1] == 1) {              //if system is on

      Serial.println("Power");      //Prints power button depressed
      digitalWrite(ONLED, LOW);     //turn off when power button pressed
      systemOn[1] = 0;              //sets state of system as off 
      // mark LEDS as off
      systemOn[2] = 0;
      systemOn[3] = 0;
      digitalWrite(convfwled, LOW); //sets conveyor forward to off
      digitalWrite(convrvled, LOW); //sets conveyor reverse to off 

    }

I’ll get an image in a moment, but tagging the code like that doesn’t seem to be doing anything, tried both CMD and CTRL

In the IDE? The Tools + Auto Format menu item is what is supposed to be triggered by CMD-T or CTRL-T.

Posting in code tags is done using the </> icon.

Your format the code in the IDE then copy/paste it here.

Use with the key combination mentioned in the IDE.

Thank you for all the help! I will use that for posting code in the future, my apologies I didn't know you could do that!It was that I didn't mark the LED's as off, by setting them equal to 0 it worked great. Thank you all!