// Source: Asgn01.SpaceshipInterfaceII.ino
// Description: This program controls a series of LEDs using two switches. Each switch activates different LED patterns.
// Programmed by: Douglas Ferreira / January 28 2024
// Variable to store the state of switch connected to pin 2
int switchState1 = 0;
// Variable to store the state of switch connected to pin 1
int switchState2 = 0;
void setup() {
// Setup function: Initializes the pins for LED outputs and switch inputs
// Initialize LED output pins
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
// Initialize switch input pins
pinMode(2, INPUT); // Switch 1
pinMode(1, INPUT); // Switch 2
}
void loop() {
// Main loop: Continuously checks switch states and controls LEDs accordingly
// Read the state of the switches
switchState1 = digitalRead(2); // Read state of switch connected to pin 2
switchState2 = digitalRead(1); // Read state of switch connected to pin 1
// Check if Switch 1 is in the LOW state (not pressed)
if (switchState1 == LOW) {
digitalWrite(3, HIGH); // Turn on LED connected to pin 3
digitalWrite(4, LOW); // Turn off LEDs connected to pins 4, 5, and 6
digitalWrite(5, LOW);
digitalWrite(6, LOW);
}
// Check if Switch 1 is HIGH (pressed) and Switch 2 is LOW (not pressed)
if (switchState1 == HIGH && switchState2 == LOW) {
digitalWrite(3, LOW); // Turn off LED connected to pin 3
// Create a blinking pattern with LEDs connected to pins 4, 5, and 6
digitalWrite(4, LOW);
digitalWrite(6, HIGH);
delay(250);
digitalWrite(5, HIGH);
delay(250);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
delay(250);
}
// Check if Switch 2 is HIGH (pressed) and Switch 1 is LOW (not pressed)
if (switchState2 == HIGH && switchState1 == LOW) {
// Turn all LEDs on and then off in a sequence
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
delay(250);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
}
// Check if Switch 2 is HIGH (pressed) and Switch 1 is HIGH too
if (switchState2 == HIGH && switchState1 == HIGH) {
// make all LEDs blink together
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
delay(500); // Keep LEDs on for half a second
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
delay(500); // Keep LEDs off for half a second
}
}