Two buttons - one output

Sorry about the long absence from this project (dental implant && medications == brain, OFF) but thanks for all the suggestions and debate.

The circuit and components - simple as it is - has been checked forwards and backwards. The two if statements work by themselves, turning the Led on or off. I.e. the innards of the Arduino are not at fault. Yet, can not get them to work together.
Went back to external pull-down resistors. Agree that debouncing should not be needed here (the two "push buttons" are in fact reed switches, reliably activated by a train to set or clear a red signal).

The post by lloyddean pretty much summarizes previous ideas, including reading the output pin as an argument in the on/off function. (is const uint8_t the same as const int; the former won't work in my version).
But OFF_BUTTON (= button2) does not work in this sketch. Not sure what serial.print could tell us here that can not be seen with the Led on pin 13.

Still open to ideas

Apologies are in order! One of my test buttons from the junkbox was a normally-on type (didn't even know they exist), keeping pin 3 high instead of low. =(
Going back to test all the code previously submitted.

telefondreng:
Going back to test all the code previously submitted.

My vote is for reply #1 and #7 :slight_smile:

Problem solved! Using hardware that actually works - plus code recommended by the Forum. Thanks again for helping out.

/*
  TWO BUTTONS  -  ONE OUTPUT
 
 Turns on a light emitting diode(LED) when pressing one pushbutton;
 and off again when pressing a second button. LED stays on in between.  
 
 The circuit:
 * LED attached from pin 13 to ground 
 * pushbuttons attached to pins 2 and 3 with 10k pull-down resistors to ground.
 
 Written 2/1/13 by
 Telefondreng.
 */

// constants used to 
// set pin numbers:
const int button1 = 2;     // the number of the 1st pushbutton pin
const int button2 = 3;         // the 2nd
const int ledPin =  13;      // the number of the LED pin



void setup()
{
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the 1st pushbutton pin as an input:
  pinMode(button1, INPUT);   
  //initialize 2nd pushbutton
  pinMode(button2, INPUT);
  
  digitalWrite (ledPin,LOW);
  
}

void loop()
{ 
  if ( digitalRead(button1))
    {
      digitalWrite (ledPin,HIGH);
    }  
  if (digitalRead(button2))
    {
      digitalWrite(ledPin,LOW);
    }  
 }