// the output pins for the display from 1 to 9
int pins[8] = {12,11,10,9,8,7,6,5}; 

//Two dimensional array containing numbers from 1-9
int num[9][7]={0,1,1,0,0,0,0,  
                1,1,0,1,1,0,1,
                1,1,1,1,0,0,1,
                0,1,1,0,0,1,1,                
                1,0,1,1,0,1,1,
                0,0,1,1,1,1,1,                
                1,1,1,0,0,0,0,
                1,1,1,1,1,1,1,
                1,1,1,0,0,1,1};
                
int touchsensorPin = 2; //input pin of the touchsensor
int potentioPin = 3; //input pin of the potentiometer
int touchData; //saves the analog input from touchsensor
int potentioData; //saves the analog input from potertiometer
int val; //contains the number according to the input of the touchsensor

// setting the pins for output and input
void setup()
{
pinMode(13, OUTPUT);  
pinMode(12, OUTPUT);  
pinMode(11, OUTPUT);  
pinMode(10, OUTPUT);  
pinMode(9, OUTPUT);  
pinMode(8, OUTPUT);  
pinMode(7, OUTPUT);  
pinMode(6, OUTPUT); 
pinMode(5, OUTPUT);   
pinMode(2,INPUT); 
pinMode(3,INPUT);
}

void loop()
{
touchData = analogRead(touchsensorPin); //reading the touchsensor
potentioData = analogRead(potentioPin); //reading the potentiometer

//Applies the range from the touchsensor to the range of the display numbers
if(touchData > 0 && touchData <= 100) {val = 0;}
if(touchData >= 200 && touchData < 300) {val = 1;}
if(touchData >= 200 && touchData < 300) {val = 2;}
if(touchData >= 300 && touchData < 400) {val = 3;}
if(touchData >= 400 && touchData < 500) {val = 4;}
if(touchData >= 500 && touchData < 600) {val = 5;}
if(touchData >= 600 && touchData < 700) {val = 6;}
if(touchData >= 700 && touchData < 800) {val = 7;}
if(touchData >= 800 && touchData < 1023) {val = 8;}

// goes through every bit of the chosen number val above and switches LED on or off
for (int i=0; i<=7; i++) 
  {
    if(num[val][i] == 1)
    {
     digitalWrite(pins[i], HIGH);
    }  
   else
    {
   digitalWrite(pins[i], LOW);
   }
  }
 delay(potentioData*2); //delays the loop according to the input of the potentiometer

}