当前位置:首页 > 科学研究 > 电子编程 > 正文内容

Arduino Project 003 - LED Traffic Light

RonWang8个月前 (06-05)电子编程108

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.

项目3 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
}

版权声明:本文为原创文章,版权归donstudio所有,欢迎分享本文,转载请保留出处!

本文链接:http://www.donstudio.cn/?id=253

标签: Arduino

相关文章

Arduino Project 030A - Dual Motor Driver L298N

Arduino Project 030A - Dual Motor Driver L298N

L298N Dual Motor Driver Project Description  The L298N Motor Driver is a control...

Arduino Programming Basic - If and Loop

Arduino Programming Basic - If and Loop

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

Arduino Project 012 - Piezo Sounder Melody Player

Arduino Project 012 - Piezo Sounder Melody Player

Rather than using the piezo to make annoying alarm sounds, why not use it to play a melody? You are...

Arduino Project 050 - IR Remote Control Light

Arduino Project 050 - IR Remote Control Light

Project 50 IR Remote Control Light/* Project 50 IR Remote Control Ligh...

Books Exploring Arduino

Books Exploring Arduino

Exploring Arduino uses the popular Arduino microcontroller platform as an instrument to teach topics...

Arduino Project 040 - Ultrasonic Distance Alarm

Arduino Project 040 - Ultrasonic Distance Alarm

The sensor consists of two primary components: a transmitter and a receiver . The transmitter is res...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。