Build a circuit and write an Arduino program to do the following: The system req
ID: 2083512 • Letter: B
Question
Build a circuit and write an Arduino program to do the following: The system requires a green LED, a yellow LED, a red LED, an ACTIVE LOW push button, an Arduino board, and wires. The system is OFF at the beginning. The Serial Monitor prints "SYSTEM IS OFF". All three LEDs are off. When the push button is pressed the first time, the green LED is ON. The red and yellow LEDs are off. The Serial Monitor prints "GREEN LED IS ON". When the push button is pressed the second time, the red LED is ON. The green and yellow LEDs are off. The Serial Monitor prints "RED LED IS ON". When the push button is pressed the third time, the yellow LED is ON. The green and red LEDs are off. The Serial Monitor prints "YELLOW LED IS ON". When the push button is pressed the fourth time, all LEDs are off. The Serial Monitor prints "SYSTEM IS OFF".Explanation / Answer
int red = 10; int yellow = 9; int green = 8; void setup(){ pinMode(red, OUTPUT); pinMode(yellow, OUTPUT); pinMode(green, OUTPUT); } void loop(){ changeLights(); delay(15000); } void changeLights(){ // green off, yellow on for 3 seconds digitalWrite(green, LOW); digitalWrite(yellow, HIGH); delay(3000); // turn off yellow, then turn red on for 5 seconds digitalWrite(yellow, LOW); digitalWrite(red, HIGH); delay(5000); // red and yellow on for 2 seconds (red is already on though) digitalWrite(yellow, HIGH); delay(2000); // turn off red and yellow, then turn on green digitalWrite(yellow, LOW); digitalWrite(red, LOW); digitalWrite(green, HIGH); delay(3000); }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.