CODE | LED Traffic Light - Arduino Project 003

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

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

STEM|60个好玩的 APP推荐

STEM|60个好玩的 APP推荐

STEAM教育理念最早是美国政府提出的教育倡议,为加强美国K12(中小学)关于科学、技术、工程、艺术以及数学的教育。STEAM的原身是STEM理念,即科学(Science)、技术(Technology…

CODE | Digital Pressure Sensor - Arduino Project 031

CODE | Digital Pressure Sensor - Arduino Project 031

Arduino Programming Basic -- Pressure SensorsPressure sensors are integral components in a multitude…

The incredible growth of Python

The incredible growth of Python

Python is a powerful programming language and Big Scope of Python   Programming Language. Pytho…

CODE | Based Security System with Lcd Display - Arduino Project 046

CODE | Based Security System with Lcd Display - Arduino Project 046

Components Needed: You will need an Arduino (like Arduino Uno or Nano), an LCD display, a keypa…

DIY T12 Soldering (Partial -Assembled Kits)

DIY T12 Soldering (Partial -Assembled Kits)

今天我们要自己动手做一台高性价比的T12焊台,我们通过DIY来体验T12的快速温升带给我们焊接的畅快。T12的焊台有什么让人着迷地方?为什么很多焊接达人,都希望拥有一台高品质的T12焊台,DIY一台T…

Application and Deployment of HTTPS Certificates

Application and Deployment of HTTPS Certificates

HTTPS证书的申请和部署超文本传输协议安全 (HTTPS) 是 HTTP 的安全版本,HTTP 是用于在 Web 浏览器和网站之间发送数据的主要协议。HTTPS 经过加密,以提高数据传输的安全性。当…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.