Chương Trình Xin Qua Đư NG Cho Ngư I Đi B

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Chương trình xin qua đường cho người đi bộ.

int button =2;

int yellow_car = 3;

int red_car =4;

int green_car =5;

int red_human =6;

void setup() {

pinMode(button,INPUT_PULLUP); // Chân D2 ngõ vào nút nhấn

pinMode(yellow_car,OUTPUT); // Chân D3 là ngõ ra đèn và xe

pinMode(red_car,OUTPUT); // Chân D4 là ngõ ra đèn đỏ xe và đèn xanh người đi bộ

pinMode(green_car,OUTPUT); // Chân D5 ngõ ra đèn xanh xe

pinMode(red_human,OUTPUT); // Chân D6 ngõ ra đèn đỏ người đi bộ

void loop() {

if(digitalRead(button)==LOW) { // ngõ vào D2 có là mức thấp hay không, mức thấp (true) mức cao
(false)

digitalWrite(green_car,LOW);
digitalWrite(yellow_car,HIGH);

delay(5000);

digitalWrite(red_human,LOW);

digitalWrite(yellow_car,LOW);

digitalWrite(red_car,HIGH);

delay(15000);

digitalWrite(red_car,LOW);

else

digitalWrite(green_car,HIGH);

digitalWrite(red_human,HIGH);

You might also like