Concept
For this assignment, I had two LEDs which would be controlled by two switches. When the switches are pressed either individually or together, the LEDs are turned on in different ways. First, pressing the swiitches one by one would turn on their corresponding LEDs and when they are pressed together, the LEDs light up, blinking in a pattern.
Diagram
CODE
void setup() { pinMode(8, OUTPUT); pinMode(13, OUTPUT); pinMode(A2, INPUT); pinMode(10, OUTPUT); pinMode(13, OUTPUT); pinMode(A3, INPUT); } void loop() { int switchPosition = digitalRead(A2); int switch2Position = digitalRead(A3); if (switchPosition == HIGH) { digitalWrite(8, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(13, LOW); } else { digitalWrite(8, LOW); // turn the LED off by making the voltage LOW digitalWrite(13, HIGH); } if (switch2Position == HIGH) { digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(13, LOW); } else { digitalWrite(10, LOW); // turn the LED off by making the voltage LOW digitalWrite(13, HIGH); } if (switchPosition == HIGH && switch2Position == HIGH) { digitalWrite(8, HIGH); // turn the LED on (HIGH is the voltage level) delay(200); // wait 0.2 seconds before turning off the LED digitalWrite(8, LOW); // turn the LED off by making the voltage LOW delay(200); // wait 0.2 seconds before turning on the LED digitalWrite(10, LOW); // turn the LED off by making the voltage LOW delay(200); // wait 0.2 seconds before turning on the LED digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level) delay(200); // wait 0.2 seconds before turning off the LED } }
VIDEO