Issue with Led's and buttons

Hello everyone, I'm having few issue doing a sketch that I really need to do 2 Led ON/OFF, controlled by 2 micro switches...
Is a recreation of a landing gear in a aircraft UP/DOWN...
When switch 1 pressed, UP LED goes alive and Down becomes LOW or 0... And the opposite when the down switch is pressed, Down LED Becomes 1 and UP LED becomes 0...I'm really struggeling to achieve that...
Can anyone help me or suggest me a sketch to make it work please?
Thanks

Yes.
Show your current sketch well formatted and in code tags.

A wiring diagram would be helpful.

Thanks for answering paul paulson,
here is my code...first things first I don't have too much knowledge about writing sketch and tried to copy one done to reply why I need to do...
Here is the sketch:

const int BUTTON1 = 2;
const int BUTTON2 = 4;
const int LED1 = 8;
const int LED2 = 12;
int BUTTONstate1 = 0;
int BUTTONstate2 = 0;

void setup()
{
  pinMode(BUTTON1, INPUT);
  pinMode(BUTTON2, INPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
}

void loop()
{
  BUTTONstate1 = digitalRead(BUTTON1);
  if (BUTTONstate1 == HIGH)
  {
    digitalWrite(LED1, HIGH);
  } 
  else{
    digitalWrite(LED1, LOW);
  }
  BUTTONstate2 = digitalRead(BUTTON2);
  if (BUTTONstate2 == HIGH)
  {
    digitalWrite(LED2, LOW);
  } 
  else{
    digitalWrite(LED2, HIGH);
  }
}

I've tried to change few of those LED HIGH and LOWS but don't worked for me...obviously it's something wrong I've done or tried to achieve in the way.
I need LED12 going on and LED8 going LOW when button 1 is pressed (single press microswitch), and opposite when button 2 is pressed.

Thanks in advance

Thanks for answering...don't have one as I copied a redone sketch to try to make it.

Hello chrisamu

Take a view here to gain the knowledge with many thanks to LarryD.

I didn't quite understand what you were trying to achieve, but here is an example of how two LEDs can be toggled.

const byte BUTTON1 = 2;
const byte BUTTON2 = 4;
const byte LED_DOWN = 8;
const byte LED_UP = 12;

void setup()
{
  pinMode(BUTTON1, INPUT_PULLUP);
  pinMode(BUTTON2, INPUT_PULLUP);
  pinMode(LED_UP, OUTPUT);
  pinMode(LED_DOWN, OUTPUT);
}

void loop()
{
  static bool stateUP {false};

  if (digitalRead(BUTTON1) == LOW) {
    stateUP = true;
  } else if (digitalRead(BUTTON2) == LOW) {
    stateUP = false;
  }

  if (stateUP) {
    digitalWrite(LED_UP, HIGH);
    digitalWrite(LED_DOWN,LOW);
  } else {
    digitalWrite(LED_UP, LOW);
    digitalWrite(LED_DOWN,HIGH);
  }
}

Here you can play around with this example:

Thank you very much for the diagram, I'll take care to do it like the diagram says...
Thanks soo much for helping I really appreciate it.

Thanks Kai-R...waiting for resistors to have a play with your sketch...I'll confirm is that is working and if my play with it works well.

Thank you soo much

You're welcome. If that fits, it would be nice if you marked the sketch in #7 as a solution.

It's working exactly like I want it...many thanks because you've solved something really important for me as my knowledge about was not alowing me to do!!
Appreciate it

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