/*
 * Code for 6 3-way switch puzzle (swch0, swch1, etc.)
 * Each switch has 3 states, those are named 0, 1, and 2 
 * Each variable can be set as  0, 1, or 2 based on what position is intended 
 
 * In order to change what state is the "correct state" for the puzzle
switch the variable value for each of the correctpos variables (correctpos0, correctpos1, etc.)

 * To change the number of switches used you must add: 
    swch, correctpos, and chck variables in lists of "Variables for array"
    swch, correctpos, and chck variables in respective arrays under "Arrays for iteration"
    Change the number i and j are less than in the for loops to one greater than number of switches
    add or remove "&& checked[#] == 1" to final if statement based on number of switches

 * Could add short wait under if statement (above "Serial.println("Correct");") to avoid playes randomly guessing correct states of switches 
 * Will eventually remove both "Serial.println" statements once puzzle is implemented
 */

void setup() {

Serial.begin(9600);

}

void loop() {

//Variables for array

int swch0 = 0;
int swch1 = 0;
int swch2 = 0;
int swch3 = 0;
int swch4 = 0;
int swch5 = 0;

int correctpos0 = 0;
int correctpos1 = 1;
int correctpos2 = 2;
int correctpos3 = 2;
int correctpos4 = 1;
int correctpos5 = 0;

int chck0 = 0;
int chck1 = 0;
int chck2 = 0;
int chck3 = 0;
int chck4 = 0;
int chck5 = 0;


// Arrays for iteration

const int analog_pins[] = {A0, A1, A2, A3, A4, A5};
int positions[] = {swch0, swch1, swch2, swch3, swch4, swch5};
int correct_pos[] = {correctpos0, correctpos1, correctpos2, correctpos3, correctpos4, correctpos5};
int checked[] = {chck0, chck1, chck2, chck3, chck4, chck5};


// Iteration to find switch positions 

for (int i=0; i < 7; i++) {
  int sensorValue = analogRead(analog_pins[i]);
  float voltage = sensorValue * (5.0/1023.0);

  if (voltage < 0.25){
    positions[i] = 1;
  }
  else if (0.25 <= voltage && voltage < 3.5){
    positions[i] = 0;
  }
  else{
    positions[i] = 2;
  };
}


//Check for switches in correct positions

for (int j=0; j<7; j++) {
  if (positions[j] == correct_pos[j]){
    checked[j] = 1;
  }
  else{
    checked[j] = 0;
  };
}

if (checked[0] == 1 && checked[1] == 1 && checked[2] == 1 && checked[3] == 1 && checked[4] == 1 && checked[5] == 1){
  Serial.println("Correct");
}
else{
  Serial.println("Incorrect");
};
}


