版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Traffic Lights交通信号灯View code on GitHub请在GitHub上查看代码Click here点击这里查看Introduction介绍In this project youre going to build a traffic lights system:在这个项目中,你将建立一个交通信号灯系统:l There are 3 LEDs with different colors (green, yellow and red) to mimic the traffic lights for the cars.用三种不同颜色的灯(绿色,黄色和红色)模拟汽车的交通信号灯l
2、There are 2 LEDs with different colors (green and red) to mimic the traffic lights for the pedestrians。用两种不同颜色(绿色和红色)的灯模拟行人的交通信号灯l There is a pushbutton to mimic the ones in the pedestrians traffic lights.有一个按钮来模仿的行人交通信号灯Parts Required零件要求Grab all the needed components for this project.获取此项目所需的所有组件。
3、l 1x Breadboardl Arduino UNO read Best Arduino Starter Kitsl 3x 5mm LED (1x red, 1x yellow, 1x green)l 2x 3mm LED (1x red, 1x green)l 5x 220Ohm Resistorl 1x 10kOhm Resistorl 1x pushbuttonl Jumper Wiresl 1x面包板l ArduinoUNO - 阅读最佳Arduino入门套件l 3x5mm LED(1x红色,1x黄色,1x绿色)l 2x3mm LED(1x红色,1x绿色)l 5x220欧姆电阻l
4、1x10k欧姆电阻l 1x按钮l 线Im using LEDs of different sizes but if you dont have LEDs of different sizes, it is ok.我用的是不同尺寸的LED,但如果你没有不同尺寸的LED,也是可以的。The project still works.该实验仍然可行。Schematics原理图Assemble all the parts by following the schematics below.按照下面的原理图组装所有零件。Code代码You dont need any library for this co
5、de. The code is very simple. Heres some tips to better understand whats going on.此代码不需要任何库。 代码非常简单。 这是一些帮你更好地理解实验过程的提示。l The car light is always green, and so the pedestrian light is always red unless someone presses the button.车灯始终为绿色,因此行人灯始终为红色,除非有人按下按钮。l When someone presses the button heres what
6、 happens:当有人按下按钮时,会发生以下情况:l The car light changes to yellow and then to red车灯变为黄色然后变为红色l The pedestrian light changes to green行人灯变为绿色l The lights are in this state for a while (in the code this time is the variable crossTime) 灯处于此状态一段时间(代码中time是变量crossTime)l The pedestrian green light flashes and go
7、es to red行人绿灯闪烁并变为红色l The car light changes from red to green车灯从红色变为绿色All these actions will be inside the function changeLights(). Everytime you want tochange the lights, you just need to call the changeLights() function.Copy the following code to your Arduino IDE, and upload it to your Arduino boa
8、rd.Make sure you have the right board and COM port selected.所有这些操作都将在函数changeLights()中。 每次你想要的改变灯光,你只需要调用changeLights()函数。将以下代码复制到Arduino IDE,并将其上传到Arduino板。确保选择了正确的板和COM端口。View code on GitHub在GitHub上查看代码/* Rui Santos* Complete Project Details */int redCar = 13;int yello
9、wCar = 12;int greenCar = 11;int greenPed = 2;int redPed = 3;int button = 7;int crossTime = 2000;unsigned long changeTime;void setup() /初始化计时器changeTime = millis();/这里我们将引脚初始化为输出pinMode(redCar, OUTPUT);pinMode(yellowCar, OUTPUT);pinMode(greenCar, OUTPUT);pinMode(redPed, OUTPUT);pinMode(greenPed, OUTP
10、UT);pinMode(button, INPUT);/打开绿灯digitalWrite(greenCar, HIGH);digitalWrite(redPed, HIGH);digitalWrite(redCar, LOW);digitalWrite(yellowCar, LOW);digitalWrite(greenPed, LOW);Serial.begin(9600);void loop() /这个变量会告诉我们按钮是否被按下int state = digitalRead(button);Serial.println(state);/如果按下按钮,并且自上次按钮起已超过5秒pressi
11、f (state = HIGH & (millis() - changeTime) 5000) /调用该功能来改变灯光changeLights();void changeLights() digitalWrite(greenCar, LOW); /绿色LED将熄灭digitalWrite(yellowCar, HIGH); /黄色LED将亮2秒钟delay(2000);digitalWrite(yellowCar, LOW); /黄色LED将熄灭digitalWrite(redCar, HIGH); /红色LED指示灯将亮起5秒钟digitalWrite(redPed, LOW);digitalWrite(greenPed, HIGH);delay(crossTime);/ 绿灯闪烁for (int x=0; x10; x+) digitalWrite(greenPed, LOW);dela
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 黑龙江省龙东地区2026年中考数学真题附同步解析
- 锅炉使用单位维修工运行操作安全操作规程
- 冬季防火防盗安全用电
- 小班触电了安全教案
- 企业人力资源管理师历年真题及答案解析(四级)
- 员工职业安全健康管理
- 钢结构安装企业主要负责人装卸作业安全操作规程
- 智慧工地成本管理系统专项施工方案
- 施工安全管理方案
- 积极预防糖尿病并发症
- 河北出版集团招聘考试题
- 2026春季海南电网有限责任公司校园招聘备考题库及参考答案详解
- GB/T 47096-2026绿色产品评价水泥
- 第三章%20村集体经济组织会计一般业务会计处理
- GB/T 5973-2026起重机械钢丝绳绳端固接接头
- 无人机驾驶员安全意识测试考核试卷含答案
- 丙肝防治培训课件
- 银行基金营销培训课件
- 2026年《必背60题》幼儿园保健医高频面试题包含详细解答
- 枪支安全理论培训课件
- 协会注销资金捐赠协议书
评论
0/150
提交评论