LED Traffic Light

by linlovely0221 in Circuits > Arduino

227 Views, 0 Favorites, 0 Comments

LED Traffic Light

WIN_20201120_09_13_21_Pro.jpg
led TRAFFIC LIGHT

這是一個有閃黃燈的LED紅綠燈

Supplies

紅黃綠LED燈各一個

usb傳輸線一條

Arduino麵包板

100歐姆電阻三個

電線數條

原作者網址

原網址: 網址

這是一個模擬紅綠燈的Arduino裝置

按原網址接上電路

WIN_20201120_09_00_52_Pro.jpg

接上電路後,將原網址提供的程式碼複製,貼到Arduino 程式上。

打開Arduino修改程式碼

修改後程式如下網址

我將綠燈的時間縮短,並把黃燈改成了閃黃燈。

int red = 10;

int yellow = 9;

int green = 8;

void setup() {

pinMode(red, OUTPUT);

pinMode(yellow, OUTPUT);

pinMode(green, OUTPUT);

}

void loop(){

changeLights();

delay(1500);//改時間縮短

}

void changeLights(){

// green off, yellow on for 3 seconds

digitalWrite(green, LOW);

digitalWrite(yellow, HIGH);

delay(3000);

// turn off yellow, then turn red on for 5 seconds

digitalWrite(yellow, LOW);

digitalWrite(red, HIGH);

delay(5000);

// red and yellow on for 2 seconds (red is already on though)

digitalWrite(yellow, HIGH);//改 黃燈閃爍

delay(400);//改

digitalWrite(yellow, LOW);//改 黃燈閃爍

delay(400);//改

digitalWrite(yellow, HIGH);//改黃燈閃爍

delay(400);//改

digitalWrite(yellow, LOW);//改黃燈閃爍

delay(400);//改

digitalWrite(yellow, HIGH);//改黃燈閃爍

delay(400);//改

// turn off red and yellow, then turn on green

digitalWrite(yellow, LOW);

digitalWrite(red, LOW);

digitalWrite(green, HIGH);

delay(1000); }//改

上傳程式碼

上傳程式碼到Arduino 裝置上

FINISH

led TRAFFIC LIGHT