//BATTY_Code //The servo library is initialized. #include // Declare variables int photoresistor = A5; int ledPinD = 6; // LEDs connected to digital pins 5 and 6 int ledPinI = 4; Servo servo; void setup() { // Pins are OUTPUTS pinMode(ledPinD, OUTPUT); pinMode(ledPinI, OUTPUT); // Photoresistor is an INPUT pinMode(photoresistor, INPUT); Serial.begin(9600); //Servo is an OUTPUT, here it is initialized servo.attach(9); } void loop() { //Photoresistor is analogic int valor = analogRead(A5); Serial.println(valor); //A light value is stablished to perform if (valor >= 200) { //Servo does 180 degree rotation in 2 seconds. Then it returns to the initial position and repeats. servo.write(200); delay(200); servo.write(-200); delay(200); //LEDs // fade in from min to max in increments of 5 points: for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { // sets the value (range from 0 to 255): analogWrite(ledPinD, fadeValue); analogWrite(ledPinI, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(5); } // fade out from max to min in increments of 5 points: for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) { // sets the value (range from 0 to 255): analogWrite(ledPinD, fadeValue); analogWrite(ledPinI, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(5); } } }