Reading and updating loop from POT continuously

As a demonstration sumulator, I’ve created a simple sketch to produce bearings either side of a centreline which is defined by a pot. So I set the centreline by the pot, then the code outputs bearings 20 degrees either side of that. When I want to reset the centre line by rotating the pot a bit, the code waits until the loop has gone all the way through it’s cycle before updating to the new centreline bearing. Now I’m nore than happy with this and it does what I want but…

What I’d really like is to reset the centre line immediately at any time by rotating the pot a bit. Currently the code waits until the loop has gone all the way through it’s cycle before updating to the new cetreline bearing. In an ideal world it would update the centreline and start the loop again as soon as there is any movement of the pot. My existing code follows…

//  Dredge_Swing_Sim.ino code created by Dene Oehme on 15/02/2019 
//  to simulate NMEA HDT Heading data to demonstrate the normal motion 
//  of a cutter suction dredge on a PC simulation

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);

float x;
float y=.1;
char outstr[100];
int(left);
int(right); 
int(width);
int(sp); 
float potPin = A0;        //  assign pot pin to a0
float readValue;


void setup() {

Serial.begin(9600);                                               // turn on serial port
pinMode(potPin,INPUT);                                        //  input from pot pin
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);     // Address 0x3C for 128x32



width = 40;          // Total swing width 
sp = 750;            // m/s between updates   1000 = one update per second

 

}

void loop(){

  readValue = analogRead(potPin);  // creates variable readAngle from analog read of the potPin
  x = ((360.0/1023.0)*readValue);  // creates the variable Angle calculated 0 to 360  

  left = (x - (width/2));
  right = (x + (width/2));


  display.clearDisplay();                    //  display to OLED
  display.setTextSize(4);
  display.setTextColor(WHITE);
  display.setTextSize(3);
  display.setCursor(0,8);
  display.print("C/L ");
  display.setCursor(55,4);
  display.setTextSize(4);
  display.print(x ,2);
  display.display(); 
  delay(1000);


    for (float x = left; x < right; x=x+y)      // swing to Port

 {

 dtostrf(x,5, 1, outstr);                   // create outstr 5 characters long and 1 decimal point
 Serial.print("$HEHDT,");                // send NMEA HDT String pre-cursor data to serial port
 Serial.print(outstr);                       // Serial print outstr
 Serial.println(",T");                       // send post-cursor required data & start a new line
 delay(sp);

      display.clearDisplay();               //  display to OLED
      display.setTextSize(4);
      display.setTextColor(WHITE);
      display.setCursor(0,3);
      display.print(outstr);
      delay(50);
      display.display();
  
}
  
  for (float x = right; x > left; x=x-y)        // swing to Starboard

 {

 dtostrf(x,5, 1, outstr);                  // create outstr 5 characters long and 1 decimal points
 Serial.print("$HEHDT,");               // send pre-cursor data to serial port
 Serial.print(outstr);                      // Serial print outstr
 Serial.println(",T");                       // send post cursor required data & start a new line
 delay(sp);

      display.clearDisplay();             //  display to OLED
      display.setTextSize(4);
      display.setTextColor(WHITE);
      display.setCursor(0,3);
      display.print(outstr);
      delay(50);
      display.display();
  }
}

First, you need to learn how NOT to use delay(...). There is a locked topic at the top of the forum that will teach you how to use millis() instead of using delay(...). delay(50) is probably not so bad, but delay(sp) and delay(1000) create long periods where you cannot react quickly because you cannot even read the potentiometer.

int(left);
int(right);
int(width);
int(sp);

Why are the brackets there ?

I too wondered about the parentheses but they seemed to be harmless except for the confusion factor.