Traffic Light

 

Rangkaian Traffic Light Dengan Proteus 8


Source code Arduino

//Konfigurasi PIN
//TF1
const int H1=0 , K1=1 , M1=2;
//TF2
const int H2=3 , K2=4 , M2=5;
//TF3
const int H3=6, K3=7, M3=8;
//TF4
const int H4=9, K4=10, M4=11;

void setup() {
  // inisialisasi Lampu
  pinMode(H1,OUTPUT);
  pinMode(K1,OUTPUT);
  pinMode(M1,OUTPUT);
  pinMode(H2,OUTPUT);
  pinMode(K2,OUTPUT);
  pinMode(M2,OUTPUT);
  pinMode(H3,OUTPUT);
  pinMode(K3,OUTPUT);
  pinMode(M3,OUTPUT);
  pinMode(H4,OUTPUT);
  pinMode(K4,OUTPUT);
  pinMode(M4,OUTPUT);
}

void loop() {
  //Kondisi 1
  digitalWrite(M1,0);
  digitalWrite(K1,0);
  digitalWrite(H1,1);
  digitalWrite(M2,1);
  digitalWrite(K2,0);
  digitalWrite(H2,0);
  digitalWrite(M3,1);
  digitalWrite(K3,0);
  digitalWrite(H3,0);
  digitalWrite(M4,1);
  digitalWrite(K4,0);
  digitalWrite(H4,0);
  delay(1000);

  //Kondisi 2
  digitalWrite(M1,0);
  digitalWrite(K1,1);
  digitalWrite(H1,0);
  digitalWrite(M2,1);
  digitalWrite(K2,0);
  digitalWrite(H2,0);
  digitalWrite(M3,1);
  digitalWrite(K3,0);
  digitalWrite(H3,0);
  digitalWrite(M4,1);
  digitalWrite(K4,0);
  digitalWrite(H4,0);
  delay(1000);
  
  //Kondisi 3
  digitalWrite(M1,1);
  digitalWrite(K1,0);
  digitalWrite(H1,0);
  digitalWrite(M2,0);
  digitalWrite(K2,0);
  digitalWrite(H2,1);
  digitalWrite(M3,1);
  digitalWrite(K3,0);
  digitalWrite(H3,0);
  digitalWrite(M4,1);
  digitalWrite(K4,0);
  digitalWrite(H4,0);
  delay(1000);

//Kondisi 4
  digitalWrite(M1,1);
  digitalWrite(K1,0);
  digitalWrite(H1,0);
  digitalWrite(M2,0);
  digitalWrite(K2,1);
  digitalWrite(H2,0);
  digitalWrite(M3,1);
  digitalWrite(K3,0);
  digitalWrite(H3,0);
  digitalWrite(M4,1);
  digitalWrite(K4,0);
  digitalWrite(H4,0);
  delay(1000);

//Kondisi 5
  digitalWrite(M1,1);
  digitalWrite(K1,0);
  digitalWrite(H1,0);
  digitalWrite(M2,1);
  digitalWrite(K2,0);
  digitalWrite(H2,0);
  digitalWrite(M3,0);
  digitalWrite(K3,0);
  digitalWrite(H3,1);
  digitalWrite(M4,1);
  digitalWrite(K4,0);
  digitalWrite(H4,0);
  delay(1000);

//Kondisi 6
  digitalWrite(M1,1);
  digitalWrite(K1,0);
  digitalWrite(H1,0);
  digitalWrite(M2,1);
  digitalWrite(K2,0);
  digitalWrite(H2,0);
  digitalWrite(M3,0);
  digitalWrite(K3,1);
  digitalWrite(H3,0);
  digitalWrite(M4,1);
  digitalWrite(K4,0);
  digitalWrite(H4,0);
  delay(1000);

//Kondisi 7
  digitalWrite(M1,1);
  digitalWrite(K1,0);
  digitalWrite(H1,0);
  digitalWrite(M2,1);
  digitalWrite(K2,0);
  digitalWrite(H2,0);
  digitalWrite(M3,1);
  digitalWrite(K3,0);
  digitalWrite(H3,0);
  digitalWrite(M4,0);
  digitalWrite(K4,0);
  digitalWrite(H4,1);
  delay(1000);

//Kondisi 8
  digitalWrite(M1,1);
  digitalWrite(K1,0);
  digitalWrite(H1,0);
  digitalWrite(M2,1);
  digitalWrite(K2,0);
  digitalWrite(H2,0);
  digitalWrite(M3,1);
  digitalWrite(K3,0);
  digitalWrite(H3,0);
  digitalWrite(M4,0);
  digitalWrite(K4,1);
  digitalWrite(H4,0);
  delay(1000);
}

Comments

Popular Posts