#define ldrNum 3

int ldrPins[3] = {10,11,12};
int led_r = 5;
int led_m = 7;
int led_l = 9;
int reading[3];
bool leftDir = true;
bool midDir = true;
bool rightDir = true;


void setup() {
  Serial.begin(115200);
  // put your setup code here, to run once:
  pinMode(led_r, OUTPUT);
  pinMode(led_m, OUTPUT);
  pinMode(led_l, OUTPUT);

  for(int i=0;i<ldrNum;i++){pinMode(ldrPins[i], INPUT);}
}

void state(){
  for (int i=0;i<ldrNum;i++){
    reading[i] = digitalRead(ldrPins[i]);
  }
}

void turnDir(){
  int left[ldrNum] = {0,1,1};
  int mid[ldrNum] = {0,1,0};
  int right[ldrNum] = {1,1,0};

  for (int i=0;i<ldrNum;i++){
    if (reading[i] != left[i]){
      leftDir = false;
      Serial.println("Not Left!");
      break;
    }
  }
  for (int i=0;i<ldrNum;i++){
    if (reading[i] != mid[i]){
      midDir = false;
      Serial.println("Not Stright!");
      break;
    }
  }
  for (int i=0;i<ldrNum;i++){
    if (reading[i] != right[i]){
      rightDir = false;
      Serial.println("Not Right!");
      break;
    }
  }
}

void Turn(){
  if(leftDir == true){
    digitalWrite(led_l,HIGH);
    Serial.println("Left!");
    delay(10);
    digitalWrite(led_l,LOW);}
  if (rightDir == true){
    digitalWrite(led_r,HIGH);
    Serial.println("Right!");
    delay(10);
    digitalWrite(led_r,LOW);}
  if (midDir == true){
    digitalWrite(led_m,HIGH);
    Serial.println("Stright!");
    delay(10);
    digitalWrite(led_m,LOW);
  }
}

void start(){
  leftDir = true;
  midDir = true;
  rightDir = true;
}

void loop() {
  // put your main code here, to run repeatedly:
  start();
  state();
  for (int i=0;i<ldrNum;i++){
  Serial.println(reading[i]);
  }
  turnDir();
  Serial.println(leftDir);
  Serial.println(midDir);
  Serial.println(rightDir);
  Turn();
  Serial.println("\n");
  delay(100);
}
A4988