//mconnels back 2 array leds variable delays

//random floor lights
const int LED_2_PIN = 2;
const int LED_3_PIN = 3;
const int LED_4_PIN = 4;
const int LED_5_PIN = 5;
const int LED_6_PIN = 6;
const int LED_7_PIN = 7;
const int LED_8_PIN = 8;

//constantly lit
const int LED_9_PIN = 9;
const int LED_10_PIN = 10;
const int LED_11_PIN = 11;
const int LED_12_PIN = 12;

//random security
const int LED_13_PIN = 13; //  
const int LED_A0_PIN = A0; //  
const int LED_A1_PIN = A1; //  
const int LED_A2_PIN = A2; //  

#define SWITCH_PIN A5

// Define the minimum and maximum delay times in milliseconds
const int MIN_DELAY_MS_1 = 1000;
const int MAX_DELAY_MS_1 = 5000;
const int MIN_DELAY_MS_2 = 1000;
const int MAX_DELAY_MS_2 = 2000;
const int LEDS_2_DELAY_MS = 5000;

void setup()
{
// Set all LED pins as output
//random room lights
pinMode(LED_2_PIN, OUTPUT);
pinMode(LED_3_PIN, OUTPUT);
pinMode(LED_4_PIN, OUTPUT);
pinMode(LED_5_PIN, OUTPUT);
pinMode(LED_6_PIN, OUTPUT);
pinMode(LED_7_PIN, OUTPUT);
pinMode(LED_8_PIN, OUTPUT);

//constantly lit

pinMode(LED_9_PIN, OUTPUT);
digitalWrite(LED_9_PIN, HIGH);
digitalWrite(LED_10_PIN, OUTPUT);
digitalWrite(LED_10_PIN, HIGH);
digitalWrite(LED_11_PIN, OUTPUT);
digitalWrite(LED_11_PIN, HIGH);
digitalWrite(LED_12_PIN, OUTPUT);
digitalWrite(LED_12_PIN, HIGH);

//random security
pinMode(LED_13_PIN, OUTPUT);
digitalWrite(LED_13_PIN, HIGH);
pinMode(LED_A0_PIN, OUTPUT);
digitalWrite(LED_A0_PIN, HIGH);
pinMode(LED_A1_PIN, OUTPUT);
digitalWrite(LED_A1_PIN, HIGH);
pinMode(LED_A2_PIN, OUTPUT);
digitalWrite(LED_A2_PIN, HIGH);


pinMode(SWITCH_PIN, INPUT);

// Seed the random number generator
randomSeed(analogRead(A7));
}

void loop()
{
// Check state of switch
bool switchState = digitalRead(SWITCH_PIN);
if (switchState == HIGH)
{
turnOnLights();
//delay(LEDS_2_DELAY_MS);
}
else
{
turnOffLights();
}
}

void turnOnLights() //turns room lights on, security lights off
{
// Create two arrays to hold the LED pins
int leds_1[] = {LED_2_PIN, LED_3_PIN, LED_4_PIN, LED_5_PIN, LED_6_PIN, LED_7_PIN, LED_8_PIN};
int leds_2[] = {LED_13_PIN, LED_A0_PIN, LED_A1_PIN, LED_A2_PIN};

// Turn on each room LED in random order for the LEDs in array leds_1[]
for (int i = 0; i < 7; i++)
{

int index = random(i, 7);
int temp = leds_1[index];
leds_1[index] = leds_1[i];
leds_1[i] = temp;
digitalWrite(leds_1[i], HIGH);
delay(random(MIN_DELAY_MS_1, MAX_DELAY_MS_1));
}
delay(LEDS_2_DELAY_MS);
// Turn off each security LED in random order for LEDs in array leds_2[]
for (int i = 0; i < 4; i++)
{
int index = random(i, 4);
int temp = leds_2[index];
leds_2[index] = leds_2[i];
leds_2[i] = temp;
digitalWrite(leds_2[i], LOW);
delay(random(MIN_DELAY_MS_2, MAX_DELAY_MS_2));
}

// Leave all room LEDs on and security lights off
//room lights
/*digitalWrite(LED_2_PIN, HIGH);
digitalWrite(LED_3_PIN, HIGH);
digitalWrite(LED_4_PIN, HIGH);
digitalWrite(LED_5_PIN, HIGH);
digitalWrite(LED_6_PIN, HIGH);
digitalWrite(LED_7_PIN, HIGH);
digitalWrite(LED_8_PIN, HIGH);
//security lights
digitalWrite(LED_13_PIN, LOW);
digitalWrite(LED_A0_PIN, LOW);
digitalWrite(LED_A1_PIN, LOW);
digitalWrite(LED_A2_PIN, LOW);*/

}

void turnOffLights() // turns room LEDs off and security lights on
{
// Create two arrays to hold the LED pins

int leds_1[] = {LED_2_PIN, LED_3_PIN, LED_4_PIN, LED_5_PIN, LED_6_PIN, LED_7_PIN, LED_8_PIN};
int leds_2[] = {LED_13_PIN, LED_A0_PIN, LED_A1_PIN, LED_A2_PIN};

// Turn on each security LED in random
for (int i = 0; i < 4; i++)
{
int index = random(i, 4);
int temp = leds_2[index];
leds_2[index] = leds_2[i];
leds_2[i] = temp;
digitalWrite(leds_2[i], HIGH);
delay(random(MIN_DELAY_MS_2, MAX_DELAY_MS_2));
}
delay(LEDS_2_DELAY_MS);

// Turn off each room LED in random order
for (int i = 0; i < 7; i++)
{
int index = random(i, 7);
int temp = leds_1[index];
leds_1[index] = leds_1[i];
leds_1[i] = temp;
digitalWrite(leds_1[i], LOW);
delay(random(MIN_DELAY_MS_1, MAX_DELAY_MS_1));
}


// Leave all room LEDs off and security LEDs on
//room lights
digitalWrite(LED_2_PIN, LOW);
digitalWrite(LED_3_PIN, LOW);
digitalWrite(LED_4_PIN, LOW);
digitalWrite(LED_5_PIN, LOW);
digitalWrite(LED_6_PIN, LOW);
digitalWrite(LED_7_PIN, LOW);
digitalWrite(LED_8_PIN, LOW);
//security
digitalWrite(LED_13_PIN, HIGH);
digitalWrite(LED_A0_PIN, HIGH);
digitalWrite(LED_A1_PIN, HIGH);
digitalWrite(LED_A2_PIN, HIGH);
}