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

Arduino Project 003 - LED Traffic Light

RonWang7个月前 (06-05)电子编程68

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://parentscn.com/?id=253

标签: Arduino

相关文章

Arduino Project 026 - Dual Servo Control

Arduino Project 026 - Dual Servo Control

This project you’ll create another simple project, but this time you’ll control two servos using com...

 Arduino Project 033 - 4 Digital 7 Segment Display

Arduino Project 033 - 4 Digital 7 Segment Display

Showing Heep and number 0-9 on a Common Anode 7-segment LED display. Displays the numbers 0-9 on the...

​Arduino Project 046 - Based Security System by Arduino with Lcd Display

​Arduino Project 046 - Based Security System by Arduino with Lcd Display

Arduino Project 046 - Based Security System by Arduino with Lcd Display/*  * Project ...

Arduino Project 032 - BMP280 Pressure Sensor LCD Display

Arduino Project 032 - BMP280 Pressure Sensor LCD Display

For this project we will use Arduino Uno and BMP280 along with LCD 16x2 display module to display te...

Arduino Project 013 - Piezo Knock Sensor

Arduino Project 013 - Piezo Knock Sensor

A piezo disc works when an electric current is passed over the ceramic material in the disc, causing...

Arduino Project 006 - LED Interactive Chase Effect

Arduino Project 006 - LED Interactive Chase Effect

Leave your circuit board intact from Project 5. You’re just going to add a potentiometer to this cir...

发表评论

访客

看不清,换一张

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