16级翻译翻译用翻译_第1页
16级翻译翻译用翻译_第2页
16级翻译翻译用翻译_第3页
16级翻译翻译用翻译_第4页
16级翻译翻译用翻译_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论