Need help with my code

I am making a small scale lightbar, and am having trouble. I'm using an IRremote library for activation of the lights so it can be mostly wireless. The problem, however, is that the code only runs once when I press the button once and does not loop. The serial monitor also has an issue where is reads every button the same, which isn't helping. I will provide more info if needed to help resolve. Thanks in advance!

// v Front Side v
const int led1 = 52; //Blue
const int led2 = 53; //Blue
const int led3 = 50; //White
const int led4 = 51; //Blue
const int led5 = 48; //IR
const int led6 = 49; //Blue
const int led7 = 46; //White
const int led8 = 47; //Blue
const int led9 = 44; //Blue
// v REAR SIDE v
const int led10 = 45; //Blue
const int led11 = 42; //Blue
const int led12 = 43; //White
const int led13 = 40; //Blue
const int led14 = 41; //Blue

#include <IRremote.h>
#define IR_RECEIVE_PIN 8
#define IR_BUTTON_1 12
#define IR_BUTTON_2 24
#define IR_BUTTON_3 94
#define IR_BUTTON_PLAY_PAUSE 64

void setup() {
  Serial.begin(9600);
  IrReceiver.begin(IR_RECEIVE_PIN);

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT); //Stating LED pins as outputs
  pinMode(led8, OUTPUT);
  pinMode(led9, OUTPUT);
  pinMode(led10, OUTPUT);
  pinMode(led11, OUTPUT);
  pinMode(led12, OUTPUT);
  pinMode(led13, OUTPUT);
  pinMode(led14, OUTPUT);
}
void loop() {
  if (IrReceiver.decode()) {
    IrReceiver.resume();
    int command = IrReceiver.decodedIRData.command;
    
      if(IR_BUTTON_1 == HIGH); {
        Serial.println("Pressed on button 1");
        
        digitalWrite(led1, HIGH);
        digitalWrite(led2, HIGH);
        digitalWrite(led4, HIGH);
        delay(50);
        digitalWrite(led1, LOW);
        digitalWrite(led2, LOW);
        digitalWrite(led4, LOW);
        delay(50);
        digitalWrite(led1, HIGH);
        digitalWrite(led2, HIGH);
        digitalWrite(led4, HIGH);
        delay(50);
        digitalWrite(led1, LOW);
        digitalWrite(led2, LOW);
        digitalWrite(led4, LOW);
        delay(50);
        digitalWrite(led1, HIGH);
        digitalWrite(led2, HIGH);
        digitalWrite(led4, HIGH);
        delay(150);               //BREAK 
        digitalWrite(led1, LOW);
        digitalWrite(led2, LOW);
        digitalWrite(led4, LOW);
        delay(50);
        digitalWrite(led3, HIGH);
        digitalWrite(led5, HIGH);
        digitalWrite(led6, HIGH);
        delay(50);
        digitalWrite(led3, LOW);
        digitalWrite(led5, LOW);
        digitalWrite(led6, LOW);
        delay(50);
        digitalWrite(led3, HIGH);
        digitalWrite(led5, HIGH);
        digitalWrite(led6, HIGH);
        delay(50);
        digitalWrite(led3, LOW);
        digitalWrite(led5, LOW);
        digitalWrite(led6, LOW);
        delay(50);
        digitalWrite(led3, HIGH);
        digitalWrite(led5, HIGH);
        digitalWrite(led6, HIGH);
        delay(150);
        digitalWrite(led3, LOW);
        digitalWrite(led5, LOW);
        digitalWrite(led6, LOW);
        delay(50); }
      
      if(IR_BUTTON_PLAY_PAUSE == HIGH);
        Serial.println("Pressed on button play/pause");
        //Pattern not yet made for this button
  }
}

Hi @hpaksi ,
Welcome to the forum..

got a stray ; in there..
and shouldn't that be == command??

same stray ; and also should ==command..
that stray ; ends it right there so the next line/block will always be executed..

good luck.. ~q

My god, thank you! The IR remote buttone are now recognized. But, the code still only runs once? I'll send the updated code:

//Code for 14-seg Mini Lightbar | Code setup 9/19/2023 - Updated 10/2/2023 ***Uses IR Receiver and remote***
// v Front Side v
const int led1 = 52; //Blue
const int led2 = 53; //Blue
const int led3 = 50; //White
const int led4 = 51; //Blue
const int led5 = 48; //IR
const int led6 = 49; //Blue
const int led7 = 46; //White
const int led8 = 47; //Blue
const int led9 = 44; //Blue
// v REAR SIDE v
const int led10 = 45; //Blue
const int led11 = 42; //Blue
const int led12 = 43; //White
const int led13 = 40; //Blue
const int led14 = 41; //Blue

#include <IRremote.h>
#define IR_RECEIVE_PIN 8
#define IR_BUTTON_1 12
#define IR_BUTTON_2 24
#define IR_BUTTON_3 94
#define IR_BUTTON_PLAY_PAUSE 64

void setup() {
  Serial.begin(9600);
  IrReceiver.begin(IR_RECEIVE_PIN);

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT); //Stating LED pins as outputs
  pinMode(led8, OUTPUT);
  pinMode(led9, OUTPUT);
  pinMode(led10, OUTPUT);
  pinMode(led11, OUTPUT);
  pinMode(led12, OUTPUT);
  pinMode(led13, OUTPUT);
  pinMode(led14, OUTPUT);
}
void loop() {
  if (IrReceiver.decode()) {
    IrReceiver.resume();
    int command = IrReceiver.decodedIRData.command;
    
      if(IR_BUTTON_1 == command) {
        Serial.println("Pressed on button 1");
        
        digitalWrite(led1, HIGH);
        digitalWrite(led2, HIGH);
        digitalWrite(led4, HIGH);
        delay(50);
        digitalWrite(led1, LOW);
        digitalWrite(led2, LOW);
        digitalWrite(led4, LOW);
        delay(50);
        digitalWrite(led1, HIGH);
        digitalWrite(led2, HIGH);
        digitalWrite(led4, HIGH);
        delay(50);
        digitalWrite(led1, LOW);
        digitalWrite(led2, LOW);
        digitalWrite(led4, LOW);
        delay(50);
        digitalWrite(led1, HIGH);
        digitalWrite(led2, HIGH);
        digitalWrite(led4, HIGH);
        delay(150);               //BREAK 
        digitalWrite(led1, LOW);
        digitalWrite(led2, LOW);
        digitalWrite(led4, LOW);
        delay(50);
        digitalWrite(led3, HIGH);
        digitalWrite(led5, HIGH);
        digitalWrite(led6, HIGH);
        delay(50);
        digitalWrite(led3, LOW);
        digitalWrite(led5, LOW);
        digitalWrite(led6, LOW);
        delay(50);
        digitalWrite(led3, HIGH);
        digitalWrite(led5, HIGH);
        digitalWrite(led6, HIGH);
        delay(50);
        digitalWrite(led3, LOW);
        digitalWrite(led5, LOW);
        digitalWrite(led6, LOW);
        delay(50);
        digitalWrite(led3, HIGH);
        digitalWrite(led5, HIGH);
        digitalWrite(led6, HIGH);
        delay(150);
        digitalWrite(led3, LOW);
        digitalWrite(led5, LOW);
        digitalWrite(led6, LOW);
        delay(50); }
      
      if(IR_BUTTON_PLAY_PAUSE == HIGH)
        Serial.println("Pressed on button play/pause");
        //Pattern not yet made for this button
  }
}

try moving this to the bottom of the loop just outside the if..

~q

it's probably all them delays in the sketch.. :frowning:
should take em all out..
simple timer based on millis would work nice..
need to keep track of the skips, simple state machine..
~q

      if(IR_BUTTON_PLAY_PAUSE == command)
        Serial.println("Pressed on button play/pause");
        //Pattern not yet made for this button
        IrReceiver.resume();
  }
}```

Like so? Still ran once, unless I have it in the wrong spot.

give me a sec, gonna simm it up..

~q

Oh :frowning_face:
Would you be able to make an example of what I'd need to do so I could use that and for future flash patterns? I'm not too good with coding lol, and this main code was from an example, I just modified it to my needs.

You could save a lot of typing by learning about arrays of variables.

In Arduino IDE, under File is Examples where the menu has 05 Control the first mini lesson is Arrays and then the next shows more how to use them. You will change how you see code!

I'll definitely look into that, thank you. I have a lot to learn just by looking at that, so I'm hoping to get my current code working and then go from there maybe.

You know, seems to be working??

MegaScaleLightBar

did have to change some things for the ir, wonder if your using a different lib..
the button codes in the sim were different too..

i did move the resume to just after the decoding the ir data..

strange.. ~q

Oh weird, yeah I'm using the IRremote library by Armin Joachimsmeyer

I'm not really sure what to do here :confused:
Was hoping it wasn't delays but it may be?

even weirder, as this one is too..
must be an older version in the sim..
~q

Oh. Yeah mine is up to date, 4.3.1

In the new one it looks like it's <IRremote.hpp. rather than .h

so, really don't need to..
but now, I'll take out the delays and move the animation into it's own function so you can easily add more..
give me a few more mins..
~q

There are several steps to learning these basic ideas that you don't want to skip at all.

A step before is learning how the different variable types work.
Like integers vs floating point and integers can be
signed or unsigned plus how many bits can be 8, 16, 32 or 64 bits/

Type int are signed 16 bit, can be -65536 to ++65535.

For pin numbers and other small values,
type byte are unsigned 8 bit, can be 0 to 255 and use half as much memory as int.

For text, type char is signed 8 bit that you can

char letter = 'A'; // more clear than = 65, compiler makes 'A' into 65.

Type unsigned long can count 0 to over 4 billion and type unsigned long long can be that squared!

AVR-duinos like Uno count by 8 bits. A 16 bit type takes twice as long to process as 8 bit. And floats... they process slowest except for powers of 10 math. They have range but lose precision and IMO are best avoided where integers can be used.
If I want to measure meters to 6 places, my unit becomes micro-meters where type long lets me have 999,999,999 == 999.999999 meters and Lightspeed == 299792485 micrometers per second.

delays are out..
leds are in an array..

added code for button 2, just copied the ani from 1..

think i got it..
link is updated..

happy coding.. ~q

Neat looking code. For some reason pressing a button still makes the flashing loop run once. Hmm. I'll have to look into making a switch box with constant input signal like I had before using the remote. I'll look into some different coding stuff too. I do appriciate the help truly @qubits-us !