How to program input switch??

Enjoy :slight_smile:

This should print to the console what the current status is:

/*
|| A police light imitator
|| One control the lights using five switches. One light on/off switch, and four mode switches or state swithes.
|| This will give the user the oppertunity to choose between four animations/patterns/modes and also to shut it off, or turn it on.
||
|| Contributed:
|| Alexander Brevig
*/

//setup code
#define DEBUG 1 //0 if serial debugging is to be turned off
#define PULLUP 1 //0 if pulldown resistors are used
#define SWITCH_PRESSED (!PULLUP)

//define states
#define LIGHT_STATE_1 0
#define LIGHT_STATE_2 1
#define LIGHT_STATE_3 2
#define LIGHT_STATE_4 3

//variables
#define LIGHT_ON_SWITCH 0 //array index 0 == pin 8, will be the on/off switch for the lights
#define NUMBER_OF_PINS 5
byte switchPin[NUMBER_OF_PINS] = { 8 , 9 , 10 , 11 , 12 }; //8 is on/off switch, 9-12 will be control switches
boolean switchValues[NUMBER_OF_PINS] = { 0 , 0 , 0 , 0 , 0 };

byte currentState = LIGHT_STATE_1;

void setup() {
//configure all switchPins as INPUT
for (byte i=0; i<NUMBER_OF_PINS; i++){
pinMode(switchPin*,INPUT);*

  • if (PULLUP){*
  • //if the internal pullup resistor is to be used, turn it on*
    _ digitalWrite(switchPin*,HIGH);_
    _
    }_
    _
    }_
    _
    if (DEBUG) { Serial.begin(9600); }_
    _
    }_
    void loop(){
    _
    //set all states*_
    * for (byte i=0; i<NUMBER_OF_PINS; i++){
    if (digitalRead(switchPin)==SWITCH_PRESSED){
    _ switchValues=true;
    }else{
    switchValues=false;
    }
    }*_

* //if lighs are on*
* if (switchValues[LIGHT_ON_SWITCH]){
_ //do logic*
* for (byte i=1; i<NUMBER_OF_PINS; i++){*
if (switchValues*){
currentState = i;
switchValues = false; //this state is now acted upon, flush it.
}
}
//execute current state*

* switch (currentState){_
case LIGHT_STATE_1: lightState1(); break;
case LIGHT_STATE_2: lightState2(); break;
case LIGHT_STATE_3: lightState3(); break;
case LIGHT_STATE_4: lightState4(); break;
_ }
}else{//if light are to be shut off, do so:
lightsOff();
}
}
void lightState1(){
//TODO - implement pattern 1*

* if (DEBUG) { Serial.println("lightState1"); }
}
void lightState2(){
//TODO - implement pattern 2*

* if (DEBUG) { Serial.println("lightState2"); }
}
void lightState3(){
//TODO - implement pattern 3*

* if (DEBUG) { Serial.println("lightState3"); }
}
void lightState4(){
//TODO - implement pattern 4*

* if (DEBUG) { Serial.println("lightState4"); }
}
void lightsOff(){
//TODO - implement lightsOff*

* if (DEBUG) { Serial.println("lightsOff"); }
}
[/quote]*_