// Define constants for pin numbers
const int LED1_PIN = 2;
const int LED2_PIN = 8;
const int LED3_PIN = 12;
const int START_SWITCH_PIN = 6;
const int SW1_PIN = 3;
const int SW2_PIN = 4;
const int SW3_PIN = 5;
// Define variables
bool circuitStarted = false;
bool switchPressed = false;
unsigned long previousMillis = 0;
const long flashInterval = 5000; // Flash interval in milliseconds
const int flashes = 2; // Number of flashes
void setup() {
// Set the LED pins as OUTPUT
pinMode(LED1_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
pinMode(LED3_PIN, OUTPUT);
// Set the switch pins as INPUT with internal pull-up resistors
pinMode(START_SWITCH_PIN, INPUT);
pinMode(SW1_PIN, INPUT_PULLUP);
pinMode(SW2_PIN, INPUT_PULLUP);
pinMode(SW3_PIN, INPUT_PULLUP);
}
// Function to flash the specified LED
void flashLED(int ledPin) {
for (int i = 0; i < flashes; i++) {
digitalWrite(ledPin, HIGH); // Turn on the LED
delay(500); // Wait for 0.5 seconds
digitalWrite(ledPin, LOW); // Turn off the LED
if (i < flashes - 1) {
delay(flashInterval); // Wait for the specified interval between flashes
}
}
}
void loop() {
// Check if the Start switch is pressed
if (digitalRead(START_SWITCH_PIN) == LOW) {
// Reset switchPressed when Start is pressed
switchPressed = false;
circuitStarted = true;
}
// If the circuit is started, check for button presses
if (circuitStarted) {
// Check and handle SW1 press
if (!switchPressed && digitalRead(SW1_PIN) == LOW) {
flashLED(LED1_PIN);
switchPressed = true;
}
// Check and handle SW2 press
if (!switchPressed && digitalRead(SW2_PIN) == LOW) {
flashLED(LED2_PIN);
switchPressed = true;
}
// Check and handle SW3 press
if (!switchPressed && digitalRead(SW3_PIN) == LOW) {
flashLED(LED3_PIN);
switchPressed = true;
}
}
}