multi pushbutton on/off

hi,

I'm a complete newbie to all this but loving it all the same just trying to add to an existing code i found for a push button on/off circuit.

I'm able to get one relay working from one switch but I'm unsure how to add extra switches to the code.
I am able to change the input and output pins but don't know where or how to add to the code to give me more switch input and outputs

Any help would be great

Thanks in advance

this is the code I'm using

/* switch
*

  • Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
  • press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
  • a minimum delay between toggles to debounce the circuit (i.e. to ignore
  • noise).
  • David A. Mellis
  • 21 November 2006
    */

int inPin = 3; // the number of the input pin
int outPin = 12; // the number of the output pin

int state = HIGH; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers

void setup()
{
pinMode(inPin, INPUT);
pinMode(outPin, OUTPUT);
}

void loop()
{
reading = digitalRead(inPin);

// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;

time = millis();
}

digitalWrite(outPin, state);

previous = reading;
}

All you need to do is look at the variables used for the existing input and output then duplicate them for the next input/output combination.
ex:
int inPin2 = 4;
int outPin2 = 13;
int state2 = HIGH;
int reading2;
int previous2 = LOW;
unsigned long time2 = 0;

BTW,
long time = 0; // the last time the output pin was toggled
millis() returns an unsigned long so change the type of 'time'.
unsigned long time = 0; // the last time the output pin was toggled

.

If you have more than 2 or 3 pins you should consider arrays:

const int inPins[3]    =  {3, 4, 5};         
const int outPins[3]   = {11, 12, 13};       
int state[3]   = {HIGH, HIGH, HIGH};      
int reading[3];           
int previous[3];  // Note: globals get initialized to zero (== LOW)    
unsigned long time[3] ;

johnwasser:
If you have more than 2 or 3 pins you should consider arrays:

const int inPins[3]    =  {3, 4, 5};         

const int outPins[3]  = {11, 12, 13};     
int state[3]  = {HIGH, HIGH, HIGH};     
int reading[3];         
int previous[3];  // Note: globals get initialized to zero (== LOW)   
unsigned long time[3] ;

Agree.

One reason you may not want to use arrays is to use meaningful names.
Not suggesting that inPin2 is a good name, but maybe frontDoorSwitch might be.

.

ok so if i add this to the setup do i also have to add to the loop?

You will have to add code to loop() similarly.

Sounds like you need to put more effort on the basic examples in the IDE.
.