# Multiple digital switches

I tried to change the code below for a multiple switches and I got a long code with so many bugs and problems.
There is any way to do this in short way, and to handle multiple press in same time?
I want to make this code for controlling relays for a smart home as school project.

The code (taken from: http://arduino.cc/en/Tutorial/Switch/) :

``````/* 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 = 2;         // the number of the input pin
int outPin = 13;       // the number of the output pin

int state = HIGH;      // the current state of the output 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()
{

// 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);

}
``````

This can be done with an array of time values, an array of pin numbers, and an
array of state values.

This can be done with an array of time values, an array of pin numbers, and an
array of state values.

And names that seem to go together. Looking at reading and previous, they don't appear to go together. Previous what?

time? Time that what happened?