
Arduino
Write a program that operates a train crossing light. The lights should flash at a rate of 2 Hz (on, off, on, off in 1 second) and operate for 20 seconds.
How do I make it operate for 20 seconds?
My code:
int RedLED = 7;
int GreenLED = 3;
void setup() {
pinMode(RedLED, OUTPUT);
pinMode(GreenLED, OUTPUT);
}
void loop() {
{
digitalWrite(RedLED, HIGH); // it will set led to on mode
delay(1000); //it will wait for 1 second before turning off the LED
digitalWrite(RedLED, LOW); // It will turn off the LED
delay(1000); // It will wait for 1 second before Turning the LED High again.
digitalWrite(GreenLED, HIGH); // it will set led to on mode
delay(1000); //it will wait for 1 second before turning off the LED
digitalWrite(GreenLED, LOW); // It will turn off the LED
delay(1000); // It will wait for 1 second before Turning the LED High again.
}
}

int RedLED = 7;
int GreenLED = 3;
void setup() {
pinMode(RedLED, OUTPUT);
pinMode(GreenLED, OUTPUT);
}
void loop() {
{
if (millis() < 20000) {
digitalWrite(RedLED, HIGH); // it will set led to on mode
delay(1000); //it will wait for 1 second before turning off the LED
digitalWrite(RedLED, LOW); // It will turn off the LED
delay(1000); // It will wait for 1 second before Turning the LED High again.
digitalWrite(GreenLED, HIGH); // it will set led to on mode
delay(1000); //it will wait for 1 second before turning off the LED
digitalWrite(GreenLED, LOW); // It will turn off the LED
delay(1000); // It will wait for 1 second before Turning the LED High again.
} else {
}
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- Given two input integers for an arrowhead and arrow body, print a right-facing arrow. Ex: If the input is: 0 1 the output is: 1 11 00000111 000001111 00000111 11 1 import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int baseChar; int headChar; /* Type your code here. */ }}arrow_forwardI am trying to create a digital clock however, it has come to my attention that I forgot to put in a main method. Is there any chance you could help me develop a main method for my program so it compiles? This is my code: public class DigitalClock { private int currentHour; private int currentMinutes; public int getHour() { return currentHour; } public void setHour(int currentHour) { this.currentHour = currentHour; } public int getMinutes() { return currentMinutes; } public void setMinutes(int currentMinutes) { this.currentMinutes = currentMinutes; } public static final int HOUR_MAX = 23; // Refactored hourly max public static final int HOUR_MIN = 0; // Refactored hourly min public static final int MINUTES_MAX = 59; // Refactored minute max public static final int MINUTES_MIN = 0; // Refactored minute min public static final int TOTAL_NUMBERS_HOURS = 24; public static final int…arrow_forwardThe fader circuit you built fades in each color. What instruction would you modify tohave the colors fade out?arrow_forward
- Write a VB.net program that will ask the user to input your favorite color, and display it as Your favorite color (inputted color)arrow_forwardThe answer is one of the options below please solve carefully and circle the correct option Please write clear .arrow_forwardthis is the code: const int BLED=9; //Blue LED on Pin 9const int GLED=10; //Green LED on Pin 10const int RLED=11; //Red LED on Pin 11const int Switch=2; //The Button is connected to pin 2boolean lastSwitch = LOW; //Last Button Stateboolean currentSwitch = LOW; //Current Button Stateint ledMode = 0; //Cycle between LED statesboolean ledOn = false;void setup(){ pinMode (BLED, OUTPUT); //Set Blue LED as OutputpinMode (GLED, OUTPUT); //Set Green LED as OutputpinMode (RLED, OUTPUT); //Set Red LED as OutputpinMode (Switch, INPUT); //Set button as input (not required)}}/** LED Mode Selection Pass a number for the LED state and set it accordingly.*/void setMode(int mode){//RED if (mode == 1) { digitalWrite(RLED, HIGH); digitalWrite(GLED, LOW); digitalWrite(BLED, LOW);} //GREENelse if (mode == 2){ digitalWrite(RLED, LOW); digitalWrite(GLED, HIGH); digitalWrite(BLED, LOW); }//BLUE else if (mode == 3) { digitalWrite(RLED, LOW); digitalWrite(GLED, LOW); digitalWrite(BLED, HIGH); } //PURPLE…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





