LCD display and Rotary encoder to measure distance

Good day.

I have a project where I need to use an Arduino, a rotary encoder and a LCD display to measure a distance.
The rotary encoder is connected to a spool with string and it measures the distance.

I need help to code and connect the components.
so far I have:
1 x Arduino
1 x Rotary encoder with push button
1 x 16 x 2 LCD display with the 12 C backpack to reduce the pins from 16 to 4

I also need assistance with writing 2 sets of code that achieve the following

Set 1:
the Arduino will be collected to a laptop and will measure the distance and record the data at set time intervals until the measuring stops. the measurements need to be displayed on the LCD screen in real time or every one or two seconds. The data needs to be recorded and be exported to text or excel file.

Set 2:
the Arduino will not be connected to a computer and will be programed beforehand and connected to only a power source and needs to measure the distance in real time or at set time intervals until the distance is measured.

below is my code so far. it does not include a section for the LCD screen.

const int clkPin=2; //the clk attach to pin 2
const int dtPin=3; //the dt attach to pin 3
const int swPin=4; //the number of the button 
int encoderVal = 0;

void setup()
{
  //set clkPin,dePin,swPin ans INPUT
  pinMode(clkPin, INPUT);
  pinMode(dtPin, INPUT);
  pinMode(swPin, INPUT);
  digitalWrite(swPin, HIGH);
  Serial.begin(9600); // initiate serial communications at 9600 bps
}

void loop()
{
  int change = getEncoderTurn();
  encoderVal = encoderVal + change;
  if(digitalRead(swPin) == LOW)//if button pull down
  {
    encoderVal = 0;
  }

  double encPrintVal = encoderVal * 6.283;
  
  Serial.print(encPrintVal, 3); //print the encoderVal on the serial monitor
  Serial.print("\t");
  Serial.print("mm");
  Serial.print("\n");
}

int getEncoderTurn(void)
{
  static int oldA = HIGH; // set the oldA as HIGH
  static int oldB = HIGH; // set the oldB as HIGH
  int result = 0;
  int newA = digitalRead(dtPin); //read the value of clkPin to newA
  int newB = digitalRead(clkPin); //read the value of dtPin to newB
  if (newA != oldA || newB !=oldB) //if the value of clkPin or the dtPin haas changed
  {
    //something has changes
    if (oldA == HIGH && newA == LOW)
    {
      result = (oldB*2 - 1);
    } 
  }
  oldA = newA;
  oldB = newB;
  return result;  
}

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

What exactly is preventing you posting your code ?

Post your code when you can using code tags when you do. See How to get the best out of this forum

I have also deleted your third topic on the same subject

Be careful because you are skating on thin ice

Sorry for the multiple posts, just was not sure where to post seeing as how my problem crosses multiple categories. When I tried to add my code as a attachment it said new users cannot post attachments, did not want to add it as part of my text, as i was not sure if it was allowed or would make it too long ?

The preferred way to post code is to right click in the IDE and select "Copy for forum" then paste it here in a post. The code tags will have been added automatically during the copy

Please edit your post and add the code tags manually by selecting the code and clicking the </> icon