I am currently working on a project including an LDR, a servo motor and LEDS. I have written the code however, when I tried to combine them the LDR controlling the servo stopped working but the LEDs are working. Please can you help combine my code so that both things can happen simultaneously.
#include <Servo.h>
Servo myservo;
const int ldrpin = A0;
const int servopin = 8;
int ldrValue;
int angle = 0;
int LED1 = 13;
int LED2 = 12;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
myservo.attach (servopin);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
ldrValue = analogRead(ldrpin);
angle = map (ldrValue, 0, 1023, 0, 270);
Serial.println(angle);
myservo.write (angle);
delay (15);
digitalWrite(LED1, HIGH);
delay(3000);
digitalWrite(LED2, LOW);
delay(3000);
digitalWrite(LED1,LOW);
delay(3000);
digitalWrite(LED2, HIGH);
delay(3000);
digitalWrite(LED2, LOW);
delay(3000);
}