Turn a servo motor with a photoresistor

Hi guys,

I am trying to control my servo by a photoresistor. When the light is interrupted 1s it should turn left and when its get interrupted like 3s it should go right.

Here is my code , I tried :

#include <Stepper.h>
#include <Servo.h>
#define sensor A0                       //Pin deklarieren
const int stepsPerRevolution = 200;     // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
Servo rampe;


const int ledPin = 7;
const int buttonPin = 2;
int an, m;
int pos = 30;
unsigned long zeit_vor;
unsigned long zeit_vor2;
const long interval = 500;
const long interval2 = 100;
float zeit1 = 0;                               //Variable definieren
int schwelle = 950;

void setup() {
  // set the speed at 120 rpm:
  myStepper.setSpeed(120);
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
  rampe.attach(13);
  rampe.write(pos);
  an = 0;
  m = 0;
 
}

void loop() {

unsigned long zeit = millis();

/*if (zeit - zeit_vor <= interval) {
  
  zeit_vor = zeit;  
}
*/

 if (analogRead(sensor) < schwelle) {
  while (analogRead(sensor) < schwelle) {
    zeit1++;
    delay(10);
  }
  zeit1 = zeit1 * 10;
  zeit1 = zeit1 /1000;
  Serial.print(zeit1);
  Serial.println("Sekunden");
  zeit1 = 0;
 }


if (zeit1 < 2) { 
  Serial.print(pos);
  if (pos <= 60){
    Serial.print("Bla");
    pos = 120;
    rampe.write(pos);
  }
    else if (pos >= 61) {
    pos = 30;
    rampe.write(pos);
    }
  zeit_vor = zeit;   
}

//if (zeit - zeit_vor2 <= interval2) {
  myStepper.step(1);
//  zeit_vor2 = zeit;   
//}
  

  }

And what does that code do (what you don't want)?

Also, what does need to happen when it's not interrupted?
And if it's interrupted for 1s, should it go directly to the left and go right if the light is still blocked 2 more seconds?

Pseudo code:

if(analogRead(LdrPin) < LighThreshold){
  lightInterrupted = true;
  
  if(!previousLightInterrupted){
    interruptMillis = millis();
  }
  
  if(millis() - interruptMillis >= 3000){
    servo.write(right);
  }
  else if(millis() - interruptMillis >= 1000){
    servo.write(left);
  }
}
previousLightInterrupted == lightInterrupted;

At the moment my code is doing nothing , I tried to implemnt my ldr , but it doesn´t work .

My servo should go one side , when it´s gets the advice and stay their and if it´s gets the advice to turn to the other side it should turn to the other side and stay their.

If the LDR says you that the time is 1s it should move left and when its says 3s to the right . just as example.

Thx for the help . I will try your code first =)

Clopperhead:
I tried to implemnt my ldr , but it doesn´t work .

Apart from any possible code issues, is the ldr wired up as a voltage divider as explained here, for example.

And is the servo powered separately with its own supply, not from the Arduino 5V?