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] |
367.67 KB, 下载次数: 2447
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed