Trouble Shoot Code For “Left Button” is not Working on Arduino Mini Powered PCB

First Time Poster Here:

I have an Arduino Pro Mini mounted to a PCB. The PCB with Arduino Pro Mini powers 4 LED’s [][][][] There are also two smaller PCB’s that have 1 LED [] on them. so it is connected like. [] --- [][][][] --- []. The LED’s blink in a specific pattern when each button is pressed. I can get the right side to work but not the left.

I have posted the code below:

const int btn_left = 3;
const int btn_right = 2;
const int LEDs_L = 11;
const int LEDs_R = 10;
const int LEDs_BL = 13;
const int LEDs_BR = 12;
int Flag_R=0;
int Flag_L=0;
int Flag_BR=0;
int Flag_BL=0;
int interval=125;
int intervalB=100;
int Delay=6000;
int ledStateR = HIGH;
int ledStateL = HIGH;
int ledStateBR = HIGH;
int ledStateBL = HIGH;

unsigned long current_millis;
unsigned long prev_millis_R;
unsigned long prev_millis_r;
unsigned long prev_millis_br;
unsigned long prev_millis_L;
unsigned long prev_millis_l;
unsigned long prev_millis_bl;

void setup()
{
// initialize the LED pins as an output:
pinMode(LEDs_L, OUTPUT);
pinMode(LEDs_R, OUTPUT);
pinMode(LEDs_BL, OUTPUT);
pinMode(LEDs_BR, OUTPUT);

// initialize the pushbutton pin as an input:
pinMode(btn_left, INPUT);
pinMode(btn_right, INPUT);
}

void loop()
{
current_millis= millis();
if ( Flag_R==0 && Flag_L==0 && Flag_BR==0 && Flag_BL==0 )
{
digitalWrite(LEDs_L, HIGH);
digitalWrite(LEDs_R, HIGH);
digitalWrite(LEDs_BL, HIGH);
digitalWrite(LEDs_BR, HIGH);
}
//
if ( digitalRead(btn_right) == HIGH)
{ Flag_R=1;
Flag_BR=1;
prev_millis_R= current_millis;
prev_millis_r= current_millis;
prev_millis_br= current_millis;
}
//
if (digitalRead(btn_left) == HIGH )
{ Flag_L=1;
Flag_BL=1;
prev_millis_L= current_millis;
prev_millis_l= current_millis;
prev_millis_bl= current_millis;
}

if (current_millis - prev_millis_R <= Delay && Flag_R==1)
{
if (current_millis - prev_millis_r >= interval)
{
prev_millis_r = current_millis;
if (ledStateR == LOW) {
ledStateR = HIGH;
} else {
ledStateR = LOW;
}
digitalWrite(LEDs_R, ledStateR);
}

if (current_millis - prev_millis_br >= intervalB)
{
prev_millis_br = current_millis;
if (ledStateBR == LOW) {
ledStateBR = HIGH;
} else {
ledStateBR = LOW;
}
digitalWrite(LEDs_BR, ledStateBR); }

}
else
{
Flag_R=0;
Flag_BR=0;
}

if (current_millis - prev_millis_L <= Delay && Flag_L==1 )
{
if (current_millis - prev_millis_bl >= interval)
{
prev_millis_bl = current_millis;
if (ledStateL == LOW) {
ledStateL = HIGH;
} else {
ledStateL = LOW;
}
digitalWrite(LEDs_L, ledStateL);
}

if (current_millis - prev_millis_l >= intervalB)
{
prev_millis_l = current_millis;
if (ledStateBL == LOW) {
ledStateBL = HIGH;
} else {
ledStateBL = LOW;
}
digitalWrite(LEDs_BL, ledStateBL);
}

}
else
{
Flag_L=0;
Flag_BL=0;
}

}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

@cstevens1011

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Thank you.

What is the pattern you are trying to create? Is it just toggling on/off at the interval rate? Also what does BL and BR stand for with the LEDs? I'm guessing Blue Left and Blue Right?

Will the left and right sides only be active one at a time, or could both sides have patterns running together?

Hi,
Can you please post a circuit diagram of you project, including power supply?
Can you please post an Exported image of your PCB pattern in jpg please?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.