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

Arduino Project 003 - LED Traffic Light

RonWang11个月前 (06-05)电子编程205

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

标签: Arduino

相关文章

C语言调试运行环境Pelles C的安装

C语言调试运行环境Pelles C的安装

C语言调试运行环境之TurboC一文介绍了在32位Windows系统下安装C语言运行环境之TubroC,但是由于TurobC只能在32位系统下运行,导致现在很多Windows10和Windows 11...

Books Exploring Arduino

Books Exploring Arduino

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

Arduino Project 028B - Basic Stepper Control (Unipolar)

Arduino Project 028B - Basic Stepper Control (Unipolar)

In this very simple project, you will connect up a stepper motor and then get the Arduino to control...

 ​Arduino Project 048 - Human Body Infrared Detector and Relay Light

​Arduino Project 048 - Human Body Infrared Detector and Relay Light

Project 48 Human Body Infrared Detector and Relay Light/*  * Coding by Ronwang&...

Arduino Programming Basic - Input and Outpput

Arduino Programming Basic - Input and Outpput

The pins on the Arduino can be configured as either inputs or outputs. This document explains the fu...

 ​Arduino Project 051 - How to Connect Remote Control

​Arduino Project 051 - How to Connect Remote Control

Project 51 How to Connect Remote Control 4 Channel to Arduino// constants won't c...