Concept:
For this assignment, I decided to create a gender reveal project. I used a red LED and a button to represent “girl,” and a blue LED and button to represent “boy.”
Implementation:
When the red button is pressed, the red LED (representing “girl”) lights up. Similarly, when the blue button is pressed, the blue LED (representing “boy”) turns on.
int yellowLED = 13; // yellow LED
int blueLED = 9; // blue LED
int yellowButton = A0; // yellow button
int blueButton = A2; // blue button
void setup() {
pinMode(yellowLED, OUTPUT);
pinMode(blueLED, OUTPUT);
pinMode(yellowButton, INPUT_PULLUP);
pinMode(blueButton, INPUT_PULLUP);
}
void loop() {
int switchPositionYellow = digitalRead(yellowButton);
int switchPositionBlue = digitalRead(blueButton);
// Check if both buttons are pressed at the same time
if (switchPositionYellow == LOW && switchPositionBlue == LOW) {
digitalWrite(yellowLED, LOW);
digitalWrite(blueLED, LOW);
delay(500);
digitalWrite(yellowLED, HIGH);
delay(500);
digitalWrite(yellowLED, LOW);
digitalWrite(blueLED, HIGH);
delay(500);
digitalWrite(blueLED, LOW);
}
// If only the yellow button is pressed
else if (switchPositionYellow == LOW) {
digitalWrite(yellowLED, HIGH); // Turn ON yellow LED
digitalWrite(blueLED, LOW); // Turn OFF blue LED
}
// If only the blue button is pressed
else if (switchPositionBlue == LOW) {
digitalWrite(yellowLED, LOW); // Turn OFF yellow LED
digitalWrite(blueLED, HIGH); // Turn ON blue LED
}
// If neither button is pressed
else {
digitalWrite(yellowLED, LOW); // Turn OFF both
digitalWrite(blueLED, LOW);
}
}
int yellowLED = 13; // yellow LED
int blueLED = 9; // blue LED
int yellowButton = A0; // yellow button
int blueButton = A2; // blue button
void setup() {
pinMode(yellowLED, OUTPUT);
pinMode(blueLED, OUTPUT);
pinMode(yellowButton, INPUT_PULLUP);
pinMode(blueButton, INPUT_PULLUP);
}
void loop() {
int switchPositionYellow = digitalRead(yellowButton);
int switchPositionBlue = digitalRead(blueButton);
// Check if both buttons are pressed at the same time
if (switchPositionYellow == LOW && switchPositionBlue == LOW) {
digitalWrite(yellowLED, LOW);
digitalWrite(blueLED, LOW);
delay(500);
digitalWrite(yellowLED, HIGH);
delay(500);
digitalWrite(yellowLED, LOW);
digitalWrite(blueLED, HIGH);
delay(500);
digitalWrite(blueLED, LOW);
}
// If only the yellow button is pressed
else if (switchPositionYellow == LOW) {
digitalWrite(yellowLED, HIGH); // Turn ON yellow LED
digitalWrite(blueLED, LOW); // Turn OFF blue LED
}
// If only the blue button is pressed
else if (switchPositionBlue == LOW) {
digitalWrite(yellowLED, LOW); // Turn OFF yellow LED
digitalWrite(blueLED, HIGH); // Turn ON blue LED
}
// If neither button is pressed
else {
digitalWrite(yellowLED, LOW); // Turn OFF both
digitalWrite(blueLED, LOW);
}
}
int yellowLED = 13; // yellow LED int blueLED = 9; // blue LED int yellowButton = A0; // yellow button int blueButton = A2; // blue button void setup() { pinMode(yellowLED, OUTPUT); pinMode(blueLED, OUTPUT); pinMode(yellowButton, INPUT_PULLUP); pinMode(blueButton, INPUT_PULLUP); } void loop() { int switchPositionYellow = digitalRead(yellowButton); int switchPositionBlue = digitalRead(blueButton); // Check if both buttons are pressed at the same time if (switchPositionYellow == LOW && switchPositionBlue == LOW) { digitalWrite(yellowLED, LOW); digitalWrite(blueLED, LOW); delay(500); digitalWrite(yellowLED, HIGH); delay(500); digitalWrite(yellowLED, LOW); digitalWrite(blueLED, HIGH); delay(500); digitalWrite(blueLED, LOW); } // If only the yellow button is pressed else if (switchPositionYellow == LOW) { digitalWrite(yellowLED, HIGH); // Turn ON yellow LED digitalWrite(blueLED, LOW); // Turn OFF blue LED } // If only the blue button is pressed else if (switchPositionBlue == LOW) { digitalWrite(yellowLED, LOW); // Turn OFF yellow LED digitalWrite(blueLED, HIGH); // Turn ON blue LED } // If neither button is pressed else { digitalWrite(yellowLED, LOW); // Turn OFF both digitalWrite(blueLED, LOW); } }