Using a potentiometer with an arduino and 7 segment display

Hi, right now I have a potentiometer controlling a 7 segment display by displaying a number based on a value given off by the potentiometer, so if I turn the potentiometer completely it will display the number 9. This is my current code:

// Pin 2-8 is connected to the 7 segments of the display.
// Pin 0 is for potentiometer
int potentiometer = 0;
int potval;

int pinA = 2;
int pinB = 3;
int pinC = 4;
int pinD = 5;
int pinE = 6;
int pinF = 7;
int pinG = 8;


// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pins as outputs.
  pinMode(pinA, OUTPUT);     
  pinMode(pinB, OUTPUT);     
  pinMode(pinC, OUTPUT);     
  pinMode(pinD, OUTPUT);     
  pinMode(pinE, OUTPUT);     
  pinMode(pinF, OUTPUT);     
  pinMode(pinG, OUTPUT);     
}

void loop() {
  potval=analogRead(potentiometer);
  if (potval>=0 && potval<=101){
    //0
    digitalWrite(pinA, LOW);   
    digitalWrite(pinB, LOW);   
    digitalWrite(pinC, LOW);   
    digitalWrite(pinD, LOW);   
    digitalWrite(pinE, LOW);   
    digitalWrite(pinF, LOW);   
    digitalWrite(pinG, HIGH);     
    }
  else if (potval>=102 && potval<=203){
     //1
    digitalWrite(pinA, HIGH);   
    digitalWrite(pinB, LOW);   
    digitalWrite(pinC, LOW);   
    digitalWrite(pinD, HIGH);   
    digitalWrite(pinE, HIGH);   
    digitalWrite(pinF, HIGH);   
    digitalWrite(pinG, HIGH);
    }
  else if (potval>=204 && potval<=305){
     //2
    digitalWrite(pinA, LOW);   
    digitalWrite(pinB, LOW);   
    digitalWrite(pinC, HIGH);   
    digitalWrite(pinD, LOW);   
    digitalWrite(pinE, LOW);   
    digitalWrite(pinF, HIGH);   
    digitalWrite(pinG, LOW);  
    }
  else if (potval>=306 && potval<=407){
    //3
    digitalWrite(pinA, LOW);   
    digitalWrite(pinB, LOW);   
    digitalWrite(pinC, LOW);   
    digitalWrite(pinD, LOW);   
    digitalWrite(pinE, HIGH);   
    digitalWrite(pinF, HIGH);   
    digitalWrite(pinG, LOW);  
    }
  else if (potval>=408 && potval<=509){
    //4
    digitalWrite(pinA, HIGH);   
    digitalWrite(pinB, LOW);   
    digitalWrite(pinC, LOW);   
    digitalWrite(pinD, HIGH);   
    digitalWrite(pinE, HIGH);   
    digitalWrite(pinF, LOW);   
    digitalWrite(pinG, LOW);     
    }
  else if (potval>=510 && potval<=611){
    //5
    digitalWrite(pinA, LOW);   
    digitalWrite(pinB, HIGH);   
    digitalWrite(pinC, LOW);   
    digitalWrite(pinD, LOW);   
    digitalWrite(pinE, HIGH);   
    digitalWrite(pinF, LOW);   
    digitalWrite(pinG, LOW);     
    }
  else if (potval>=612 && potval<=713){
    //6
    digitalWrite(pinA, LOW);   
    digitalWrite(pinB, HIGH);   
    digitalWrite(pinC, LOW);   
    digitalWrite(pinD, LOW);   
    digitalWrite(pinE, LOW);   
    digitalWrite(pinF, LOW);   
    digitalWrite(pinG, LOW);     
    }
  else if (potval>=714 && potval<=815){
    //7
    digitalWrite(pinA, LOW);   
    digitalWrite(pinB, LOW);   
    digitalWrite(pinC, LOW);   
    digitalWrite(pinD, HIGH);   
    digitalWrite(pinE, HIGH);   
    digitalWrite(pinF, HIGH);   
    digitalWrite(pinG, HIGH);      
    }
  else if (potval>=816 && potval<=917){
    //8
    digitalWrite(pinA, LOW);   
    digitalWrite(pinB, LOW);   
    digitalWrite(pinC, LOW);   
    digitalWrite(pinD, LOW);   
    digitalWrite(pinE, LOW);   
    digitalWrite(pinF, LOW);   
    digitalWrite(pinG, LOW);         
    }
  else if (potval>=917 && potval<=1023){
    //9
    digitalWrite(pinA, LOW);   
    digitalWrite(pinB, LOW);   
    digitalWrite(pinC, LOW);   
    digitalWrite(pinD, HIGH);   
    digitalWrite(pinE, HIGH);   
    digitalWrite(pinF, LOW);   
    digitalWrite(pinG, LOW);         
    }
    
    
    

}

What I am trying to do is make it so if I turn the potentiometer completely, it will display all the numbers from 0-9 after a delay and if I turn it half way, it displays all the numbers from 0-5 after a delay, So, how would I go about doing this? Thanks in advance.

What do you mean by "after a delay"? How long a delay?

What should happen if you turn the pot from half way to all the way?

What should happen if, during a delay, the pot is turned to a different value?

Look at the map() function to turn the reading ( 0 - 1023 ) on the analog pin into an integer 0 - 9.
Put the segment control into a byte array so that, for example, the integer 7 (segments a,b and c powered) is represented by 00000111 and use bitRead() to interpret it. This is much more compact than your solution.
You've then got to detect a change in the number to be displayed (0-9) (i.e. someone changes the value on the potentiometer) and then count from 0 to that number with, say, a 1 second delay, displaying each digit and leaving the display showing the final digit.

I understand the map function and byte array control, thanks for that. However, I do not understand how I would go about detecting a change from one value to another, without any values in between.

For example, if I have the code set to display the numbers (0- the max value depending on the mapped value) and I quickly turn the potentiometer to change the mapped value to a 9 then the display will begin displaying random numbers because it will go from 0-1, to 0-2, to 0-3 and so on quickly. So how would I prevent this and just make it show 0-9 each for a second instead of doing the function given for each mapped value?

Thanks in advance once again.

You wait until the reading derived from the potentiometer has been stable for a period (say 500 mS) before beginning the count up series.

tahaa17:
I understand the map function

But you didn't use it.

Code to try map with delay on the serial monitor.
Leo..

int mappedPotvalue;
int number = 0; // can be used in switch case of final code

void setup() {
  Serial.begin(9600);
  Serial.println(number); // start somewhere
}

void loop() {
  mappedPotvalue = map(analogRead(A0), 0, 921, 0, 9);
  if (number != mappedPotvalue) // if not the same
  {
    delay(1000); // should be replaced with millis() timing
    if (number < mappedPotvalue) number ++; // if too low
    else number --; // if too high
    Serial.println(number);
  }
}