Selamat malam guys, semoga para pembaca mendapatkan rahmat
dan kesehatan dari Allah Swt. Pada hari yang berbahagai ini, saya akan
membagikan sedikit ilmu tentang arduino uno. Dimana pengaplikasiannya pada traffic
light.
Gambar Ilustrasi
Gambar
Skematik
Berikut listing program di bawah ini:
int red1 = 7;
int yellow1 =4;
int green1 =2;
int red2 = 8;
int yellow2 = 12;
int green2 = 13;
int timer = 10000;
void setup() {
// put your setup code
here, to run once:
// Traffic light 1
pinMode(red1,OUTPUT);
pinMode(yellow1,OUTPUT);
pinMode(green1,OUTPUT);
//traffic light 2
pinMode(red2,OUTPUT);
pinMode(yellow2,OUTPUT);
pinMode(green2,OUTPUT);
}
void loop() {
// put your main code
here, to run repeatedly:
digitalWrite(red1,HIGH);
digitalWrite(yellow1,LOW);
digitalWrite(green1,LOW);
digitalWrite(red2,LOW);
digitalWrite(yellow2,LOW);
digitalWrite(green2,HIGH);
delay(timer);
digitalWrite(red2,LOW);
digitalWrite(yellow2,HIGH);
digitalWrite(green2,LOW);
digitalWrite(red1,HIGH);
digitalWrite(yellow1,HIGH);
digitalWrite(green1,LOW);
delay(3000);
digitalWrite(red1,LOW);
digitalWrite(yellow1,LOW);
digitalWrite(green1,HIGH);
digitalWrite(red2,HIGH);
digitalWrite(yellow2,LOW);
digitalWrite(green2,LOW);
delay(timer);
digitalWrite(red2,HIGH);
digitalWrite(yellow2,HIGH);
digitalWrite(green2,LOW);
digitalWrite(red1,LOW);
digitalWrite(yellow1,HIGH);
digitalWrite(green1,LOW);
delay(3000);
}
Selamat Belajar.. Semoga Bermanfaat..