motorized ambient light sensor box

So i’m going to start by saying that I am not well versed in most of what the Arduino UNO can do. What i’m trying to accomplish is having the arduino execute code that will rotate a stepper motor to given position then stop. A ambient light sensor then will activate the motor when a set threshold is reached to rotate back to its starting position. I’m not sure how to code it to were it will loop checking the ambient sensor without repeating the first motor rotation. Then exacting the second rotation with it being thrown into a endless loop that will stop it from repeating the entire program. Here is what I’ve been working with so far. (Sorry for the messy code, I googled most of it) The Prints were me attempting too troubleshoot.
What i’m using: Arduino UNO, 28BYJ-48 stepper motor, ULN2003 Driver Board,and UCNL4010 proximity/light sensor.

#include <Stepper.h>
#include <Wire.h>
#include "Adafruit_VCNL4010.h"

Adafruit_VCNL4010 vcnl;


const int stepsPerRevolution = 2048;
boolean runA = true;
int ambLim = 80;

Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);

void setup() {
  
  myStepper.setSpeed(10);
  
  Serial.begin(9600);
}

void loop() {

  Serial.println("program start");
  Serial.println(runA);

  if (runA == true)
    {
      delay(2000);
   // Step one revolution in one direction:
    Serial.println("open");
    myStepper.step(stepsPerRevolution * 2);
    
    runA = false;
    delay(1000);
    Serial.println(runA);
    delay(1000);
    }
    
      Serial.println("waiting for sensor");
      delay(1000);
      Serial.print("Ambient: "); Serial.println(vcnl.readAmbient());
      delay(1000);
      Serial.print("Proximity: "); Serial.println(vcnl.readProximity());
      delay(500);
      
      if(vcnl.readAmbient() > ambLim)
        {
          Serial.println("close");
          delay(3000);
          myStepper.setSpeed(10);
          myStepper.step(-stepsPerRevolution * 2);
        }

}

I would use a state machine -- a variable holds the current machine state, e.g. initialized, motor is rotating to start position, measuring illumination, motor is rotating back, as needed. If or switch case carry out appropriate actions for the current state.

Google will find tutorials.

The first step in a project is to understand what you are working with. Do you have a simple program that makes the stepper motor turn one direction, stop and rotate the opposite direction?

Do you have a program that reads and prints the ambient light level and does it work the way you expect it to?

When those steps are complete, then think about how you want to make it all work together, using what you have learned.

Oh, and how does the stepper motor make the car move?

Paul