// two sequence lights
const int LED_1_PIN = 2;
const int LED_2_PIN = 3;
const int LED_3_PIN = 4;
const int LED_4_PIN = 5;
const int LED_5_PIN = 6;
const int LED_6_PIN = 7;
#define switch A5
// Define the delay between turning on each LED
const int DELAY_MS = 500;
void setup()
{
// Set all LED pins as output
pinMode(LED_1_PIN, OUTPUT);
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(switch, INPUT);
// Seed the random number generator
randomSeed(analogRead(A7));
}
void loop() {
//check state of switch
bool switchState=digitalRead(switch);
if(switchState==HIGH){
turnonlights();}
else{
turnofflights();;
}
}
//*****************************************
void turnonlights()
{
// Create two arrays to hold the LED pins
int leds_1[] = {LED_1_PIN, LED_2_PIN, LED_3_PIN};
int leds_2[] = {LED_4_PIN, LED_5_PIN, LED_6_PIN};
// Shuffle each array to randomize the order of the LEDs
for (int i = 0; i < 3; i++) {
int j = random(3);
int temp = leds_1[i];
leds_1[i] = leds_1[j];
leds_1[j] = temp;
j = random(3);
temp = leds_2[i];
leds_2[i] = leds_2[j];
leds_2[j] = temp;
}
// Turn on each LED in the shuffled order for the first three LEDs
for (int i = 0; i < 3; i++) {
digitalWrite(leds_1[i], HIGH);
delay(DELAY_MS);
}
// Turn on each LED in the shuffled order for the last three LEDs with a delay of 800ms
for (int i = 0; i < 3; i++) {
digitalWrite(leds_2[i], HIGH);
delay(800);
}
// Leave all LEDs on
digitalWrite(LED_1_PIN, HIGH);
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);
}
//*****************************************
void turnofflights()
{
// Create two arrays to hold the LED pins
int leds_1[] = {LED_1_PIN, LED_2_PIN, LED_3_PIN};
int leds_2[] = {LED_4_PIN, LED_5_PIN, LED_6_PIN};
// Shuffle each array to randomize the order of the LEDs
for (int i = 0; i < 3; i++) {
int j = random(3);
int temp = leds_1[i];
leds_1[i] = leds_1[j];
leds_1[j] = temp;
j = random(3);
temp = leds_2[i];
leds_2[i] = leds_2[j];
leds_2[j] = temp;
}
// Turn off each LED in the shuffled order for the first three LEDs
for (int i = 0; i < 3; i++) {
digitalWrite(leds_1[i], LOW);
delay(DELAY_MS);
}
// Turn off each LED in the shuffled order for the last three LEDs with a delay of 800ms
for (int i = 0; i < 3; i++) {
digitalWrite(leds_2[i], LOW);
delay(800);
}
// Leave all LEDs off
digitalWrite(LED_1_PIN, LOW);
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);
}