Keep LED on and when combining inputs turn off

Hello, just start with the programming for arduino and as mentioned in the title the project I do is that I have 4 inputs (push button) and 4 outputs (LEDs), what I try to do is that led 1 at the time Pressing your push button will turn on and stay on even if you stop pressing it and then when you activate the remaining inputs at the same time the led that will stay on will turn off. I would greatly appreciate your help, Thanks.

this is the code i’ve made. i’m using arduino one

#define LED    10
#define BUTTON     5

#define LED1      11
#define BUTOON1    7

#define LED2      12
#define BUTTON2    8

#define LED3      13
#define BUTTON3    9




void setup () {
  pinMode(10, OUTPUT);
  pinMode(5, INPUT);
  
  pinMode(11, OUTPUT);
  pinMode(7, INPUT);

  pinMode(12, OUTPUT);
  pinMode(8, INPUT);

  pinMode(13, OUTPUT);
  pinMode(9, INPUT);

}

void loop () {
  if (digitalRead (5) == HIGH) {
    digitalWrite(10, HIGH);
    if ((digitalRead (7) == HIGH) && (digitalRead (8)== HIGH) && (digitalRead (9) == HIGH)) {
      digitalWrite(10, LOW);
    }
    else { 
      digitalWrite(10, HIGH);
    }
  }

  if (digitalRead (7) == HIGH) {
    digitalWrite(11, HIGH);
  }
  else {
    digitalWrite(11, LOW);
  }

  if (digitalRead (8) == HIGH) {
    digitalWrite(12, HIGH);
  }
  else {
    digitalWrite(12, LOW);
  }

  if (digitalRead (9) == HIGH) {
    digitalWrite(13, HIGH);
  }
  else {
    digitalWrite(13, LOW);
  }
}

Hi,
Go and look at your code, you define names to pin numbers then don't use them.

For example some bits of your code;

#define LED    10
#define BUTTON     5

pinMode(10, OUTPUT);
pinMode(5, INPUT);

can be more informative

#define LEDPin    10
#define BUTTONPin     5

pinMode(LEDPin, OUTPUT);
pinMode(BUTTONPin, INPUT);

And using the pin names through your code instead of numbers will make it more readable.
Tom... :slight_smile:

Also, you could use the safer alternative

const byte LedPin = 10;
const byte ButtonPin = 5;

pinMode(LedPin, OUTPUT);
pinMode(ButtonPin, INPUT); //If you don't have an external resistor use INPUT_PULLUP

Extra bonus, the errors are a lot more descriptive as well.

And for the project, use state change detection. And if you use the Bounce2 library it does the heavy lifting for you, including debounce :slight_smile:

Hello and thanks for your answers, just change the pushbutton by a DipSwitch to avoid keeping the button pressed, and sorry for not having changed the name defined in each pin, it was in an attempt to make the code work hahahaha i will investigate that library