calibrating ldr and stepper

Hello, and welcome me ; ) I'm an absolute forum noob, so I may be utterly frustrating or overly entertaining or perhaps both. I'll cut to the chase. Building my own laser harp, preferably from scratch. It's Already pieced together and housed, functioning and a good amount of code is written.

I'm just not happy with my calibration. It's fairly steady, but bright lights will effect it in odd ways, so, I'm struggling for more control.

Key components: Uno 5mw green laser Ldr Mirror Bipolar stepper 200steps per rev A4988 driver

My problem/desire. 1. Need to EFFICIENTLY store analog input levels from the ldr as my reflected beam spins, passing the beam over the ldr once per rev. A. Efficiently, meaning, I'd like to reserve as much free memory for later as possible for other functions B. I'd preffer the calculations not to affect the speed of the steppers rotation.

  1. I can store the highest and lowest values it recieves but it is overwriting values, over time until it reaches 1, Which is not the average min.... And that just RUINS EVERYTHING. sigh.

3 I would like to temporarily record each of the 200 steps' values as often as possible, (per revolution) or at least 100 of them, maybe less . in time I will decide. (Over all, I am weary of 200 variables and their effect on the system.)

  1. And, I would like the system to know which steps the highest and lowest of those values,( per revolution,) were. which I will utilize in multiple ways later.

I may use this refinement of data on power up, and occasional, maybe by a switch,/gesture between songs Or catastrophic events.

I'm embarrassed to show my code since it is a WIP, not complete and I have chunks of useless code and notes everywhere, but I can typically integrate code well. Also, I'm not having any errors so to speak (besides the laser not pointing upward due to other bright lights, but it's rare) and i feel posting my (let's say messy) code straight off the bat may actually complicate a reply. Example code would be most useful (maybe this belongs in a strictly code section.)

Thanks for your support ; )

Whoa whoa. I wasn’t expecting that much help from the arduino community.
It’s ok.
I found a solution.

And to actually help others that may be in the same situation, I’ve decided to be bold enough to post my code.

I realized that with having the min and max. reported values, i could just avoid a slew of variables and just count through the steps and stop when i get a significant drop in value, and the min value is reported .
i might not get an average , but by letting it cycle 5 tones, I’m likely to receive an accurate portrail of the point i am most concerned about.
Then i adjust 20steps to end up,straight up.

This is by no means complete code and is just a calibration/alignment loop.

 const int sensorPin1 = A0; 
 const int sensorPin2 = A1;
const int laserPin = 4;      
const int directionPin = 10; 
const int stepPin = 11; 

int sensorValue = 0;  
int sensorMin = 255; 
int sensorMax = 0;
int pulseWidthMicros = 1; 
int millisbetweenSteps = 1; 
int rot = 0; byte x = 0; int z = 0; int y = 0;

void setup() 
{ pinMode(directionPin, OUTPUT); 
 pinMode(stepPin, OUTPUT); 
 pinMode(laserPin, OUTPUT); 
  digitalWrite(laserPin, HIGH);  
 digitalWrite(directionPin, HIGH);  
 Serial.begin(9600); }

void loop() 
for (z=0;z<5;z++)
  { setANDstep(200);
  digitalWrite(laserPin, LOW);
    for (z=0;z<y;z++) 
  { stepfunct();
    for (z=0;z<20;z++) 
    digitalWrite(laserPin, HIGH);

int setANDstep(byte x)
{   for (rot = 0; rot < x; rot++)        
    { sensorValue = analogRead(sensorPin1);
        if (sensorValue > sensorMax)   
            {sensorMax = sensorValue; }
        if (sensorValue < sensorMin)    
           { sensorMin = sensorValue; y = rot; }

int stepfunct()
{   digitalWrite(directionPin, HIGH);
 digitalWrite(stepPin, HIGH);
 digitalWrite(stepPin, LOW);

a video demonstrating the final function