#include <HCSR04.h> // we include the distance sensor library
#include <Servo.h>  // now we include the servo motor library

Servo myservo1; // we declare the six servos we are using
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
Servo myservo6;

UltraSonicDistanceSensor distanceSensor(13, 12);  // Initialize sensor that uses digital pins 13 and 12 for the trigger and the echo pins of the sensor
int angle;
int led = 10; // the led is in the pin 10
int LDR = A0; // the photoresistor is connected in pin A0
int limite = 400; // this is the light value that activates the leds

void setup () {
  
    myservo1.attach(A2);  // we declare in which pins the servos are connected
    myservo2.attach(9);
    myservo3.attach(6);
    myservo4.attach(5);
    myservo5.attach(3);
    //myservo6.attach(A5);
    
    pinMode(led, OUTPUT); // we declaare the led as an output
    pinMode(LDR, INPUT);  // and the photoresistor as an input
    Serial.begin(9600);
}

void loop () {
  
    angle = map(distanceSensor.measureDistanceCm(), 40, 0, 0, random(0,120)); // here we declare that the angle of the servo changes in function oh the value the distance servo reads, and moves in a random angle
    {
    myservo1.write(angle);  // all the servos (eyes) follow the same instruction
    myservo2.write(angle);
    myservo3.write(angle);
    myservo4.write(angle);
    myservo5.write(angle);
    myservo6.write(angle);
    delay(150);
}
    int sensorValue = analogRead(LDR);
   if (sensorValue < limite) { // if the photoresistor reads a value under the limit, the leds turn on
      digitalWrite(led, HIGH);

   }
   if (sensorValue > limite) { // if the photoresistor reads a value over the limit, the leds turn off
      digitalWrite(led, LOW);
   }
  
  Serial.println(sensorValue); // this is to see the value of light the photoresistor is reading 
}
