[项目]交通灯

2019-5-30 08:46:25 [显示全部楼层]
3710浏览
查看: 3710|回复: 1

[项目] 交通灯

[复制链接]
http://fanyapbl.chaoxing.com/pbl/bbs/preview?dataId=154778
任务名称:路**通灯
组员姓名:李羿东 舒涛 刘严发

一、任务概述
按题目要求设计面包板,路口红灯亮时人行道红灯亮,路口绿灯亮时人行道绿灯亮。
二、硬件设计
[mw_shl_code=applescript,true]int carRed = 12; //红灯输入
int carYellow = 11;//黄灯输入
int carGreen = 10;//绿灯输入
int pedRed = 9; //路口红灯输入
int pedGreen = 8;//路口绿灯输入
int button = 2; //初值
int crossTime = 5000;
unsigned long changeTime;
void setup() {
pinMode(carRed, OUTPUT);
pinMode(carYellow, OUTPUT);
pinMode(carGreen, OUTPUT);
pinMode(pedRed, OUTPUT);
pinMode(pedGreen, OUTPUT);
pinMode(button, INPUT);
digitalWrite(carGreen, HIGH);
digitalWrite(pedRed, HIGH);
}
void loop() {
int state = digitalRead(button);
if (state == HIGH && (millis() - changeTime) > 5000) {
changeLights();
}
}
void changeLights() {
digitalWrite(carGreen, LOW);
digitalWrite(carYellow, HIGH);
delay(3000);//延时三秒
digitalWrite(carYellow, LOW);
digitalWrite(carRed, HIGH);
delay(1000);
digitalWrite(pedRed, LOW);
digitalWrite(pedGreen, HIGH);
delay(crossTime);
for (int x=0; x<10; x++) {
digitalWrite(pedGreen, HIGH);
delay(250);
digitalWrite(pedGreen, LOW);
delay(250);
}
digitalWrite(pedRed, HIGH);
delay(500);
digitalWrite(carYellow, HIGH);
digitalWrite(carRed, LOW);
delay(1000);
digitalWrite(carGreen, HIGH);
digitalWrite(carYellow, LOW);
changeTime = millis();
}[/mw_shl_code]

交通灯图2
交通灯图3
交通灯图1

路**通灯.pdf

367.67 KB, 下载次数: 2447

gada888  版主

发表于 2019-5-31 06:49:14

支持,讲解详细
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
关于楼主
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail