Traffic Density Code
Traffic Density Code
int i=0;
int j=0;
void setup() {
// put your setup code here, to run once:
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);
Serial.begin(9600);
int delayTime = 1000;
updateLEDs(0);
updateLEDs(2);
// delay(delayTime);
Serial.println("traffic light");
}
void loop() {
// put your main code here, to run repeatedly:
int road_density_count[4] ={0,0,0,0};
int max_rush=0;
int max_rush_road =0;
for(int i=0;i<4;i++){
for(int j=0;j<3;j++){
// Serial.println("=");
if(digitalRead(road[i][j]) ==HIGH){
road_density_count[i] = road_density_count[i]+road_density[i][j];
Serial.print(" road_density_count[");
Serial.print(i);
Serial.print("]:");
Serial.println(road_density_count[i]);
delay(1000);
}
}
}
for(i=0;i<4;i++){
Serial.println(road_density_count[i]);
if(road_density_count[i]==1||road_density_count[i]==4||
road_density_count[i]==9){
}
else{
road_density_count[i]=0;
}
}
for(i=0;i<4;i++){
if(road_density_count[0]<road_density_count[i]){
road_density_count[0]=road_density_count[i];
max_rush = road_density_count[0];
max_rush_road =i;
Serial.print("max_rush_road: ");
Serial.println(max_rush_road);
delay(1000);
}
}
Serial.print("max_rush_road: ");
Serial.println(max_rush_road);
if(max_rush!=0){
Serial.print("rush_road: ");
Serial.print(max_rush_road);
Serial.print(" Max. Rush: ");
Serial.println(max_rush);
}
1. We transfer the program from the compiler to the memory of the micro-controller.