CODE | LED Traffic Light - Arduino Project 003

RonWang3 years ago (2023-05-22)电子编程 COD10

You are now going to create a set of traffic lights that will change from green to red, via amber, and back again, after a set length of time using the four-state UK system. This project could be used to make a set of working traffic lights for a model railway or for a child’s toy town. If you’re not from the UK, you can modify the code and colors to make them work like the traffic lights in your own country. First, though, make the project as it is and change it once you know how it works.

Project 3 -LED Traffic Lights

03 Traffic Light Circuit

03 Traffic Light Schematic



/* Coding Ron Wang
   June 4th 2024
   Autaba support for coding hardware
 */
// Project 3 - LED Traffic Lights

int ledDelay = 10000; // delay in between changes
int redPin = 10;
int yellowPin = 9;
int greenPin = 8;
void setup() {
 pinMode(redPin, OUTPUT);
 pinMode(yellowPin, OUTPUT);
 pinMode(greenPin, OUTPUT);
}
void loop() {
 digitalWrite(redPin, HIGH); // turn the red light on
 delay(ledDelay); // wait 5 seconds
 digitalWrite(yellowPin, HIGH); // turn on yellow
 delay(2000); // wait 2 seconds
 digitalWrite(greenPin, HIGH); // turn green on
 digitalWrite(redPin, LOW); // turn red off
 digitalWrite(yellowPin, LOW); // turn yellow off
 delay(ledDelay); // wait ledDelay milliseconds
 digitalWrite(yellowPin, HIGH); // turn yellow on
 digitalWrite(greenPin, LOW); // turn green off
 delay(2000); // wait 2 seconds
 digitalWrite(yellowPin, LOW); // turn yellow off
 // now our loop repeats
}
Share with Friends:

Related Articles

C02 | The Concept of Algorithms

C02 | The Concept of Algorithms

C语言教程02:算法的概念算法(Algorithm)是在有限步骤内求解某一问题所使用的一组定义明确的规则。计算机算法 是用计算机求解一个具体问题或执行特定任务的一组有序的操作步骤(或指令),是构成计算…

CODE | Pulsating Lamp - Arduino Project 007

CODE | Pulsating Lamp - Arduino Project 007

You are now going try a more advanced method of controlling LEDs. So far, you have simply turned the…

CODE | Ultrasonic Distance Display - Arduino Project 039

CODE | Ultrasonic Distance Display - Arduino Project 039

Ultrasonic sensors measure distance by sending and receiving the ultrasonic wave. The ultrasonic sen…

CODE | MX1508 H-Driver Motor - Arduino Project 030B

CODE | MX1508 H-Driver Motor - Arduino Project 030B

MX1508 H-BridgeDual Motor DriverThe driver can drive up to two motors. The H-Bridge dual motor drive…

CODE | Funcation - Arduino Programming Basic

CODE | Funcation - Arduino Programming Basic

Arduino 程序基础,介绍Arduino程序的基本组成,第一部分编写了10个例子,关于变量及变量名称,串口监视器,if循环,for循环,while循环等。第二部分介绍了函数,全局变量,局部变量和静…

About Arduino WIKI

About Arduino WIKI

Arduino (/ɑːrˈdwiːnoʊ/) is an open-source hardware and software company, project, and user community…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.