//parameters
#define POT_MIN 0
#define POT_MAX 1023
#define MIN_LIMIT 50
#define MAX_LIMIT 99
//Potentiometer Input
#define POT A0
//Digit1 seven segment display lights
#define SD1_A 22
#define SD1_B 24
#define SD1_C 26
#define SD1_D 28
#define SD1_E 30
#define SD1_F 32
#define SD1_G 34
#define SD1_DP 36 
// Digit2 seven segment display lights
#define SD2_A 23
#define SD2_B 25
#define SD2_C 27
#define SD2_D 29
#define SD2_E 31
#define SD2_F 33
#define SD2_G 35
#define SD2_DP 37
// Digit3 seven segment display lights
#define SD3_A 39
#define SD3_B 41
#define SD3_C 43
#define SD3_D 45
#define SD3_E 47
#define SD3_F 49
#define SD3_G 51
#define SD3_DP 53

// Digit2 seven segment display
int sevensegment[] = {23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53,22,24,26,28,30,32,34,36};
int LEDS[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11,12};
// functions area


// Digit2 seven segment display functions
void Digit2_zero()
{
  digitalWrite(SD2_A, HIGH);
  digitalWrite(SD2_B, HIGH);
  digitalWrite(SD2_C, HIGH);
  digitalWrite(SD2_D, HIGH);
  digitalWrite(SD2_E, HIGH);
  digitalWrite(SD2_F, HIGH);
  digitalWrite(SD2_G, LOW);
}
void Digit2_one()
{
  digitalWrite(SD2_A, LOW);
  digitalWrite(SD2_B, HIGH);
  digitalWrite(SD2_C, HIGH);
  digitalWrite(SD2_D, LOW);
  digitalWrite(SD2_E, LOW);
  digitalWrite(SD2_F, LOW);
  digitalWrite(SD2_G, LOW);
}
void Digit2_two()
{
  digitalWrite(SD2_A, HIGH);
  digitalWrite(SD2_B, HIGH);
  digitalWrite(SD2_C, LOW);
  digitalWrite(SD2_D, HIGH);
  digitalWrite(SD2_E, HIGH);
  digitalWrite(SD2_F, LOW);
  digitalWrite(SD2_G, HIGH);
}
void Digit2_three()
{
  digitalWrite(SD2_A, HIGH);
  digitalWrite(SD2_B, HIGH);
  digitalWrite(SD2_C, HIGH);
  digitalWrite(SD2_D, HIGH);
  digitalWrite(SD2_E, LOW);
  digitalWrite(SD2_F, LOW);
  digitalWrite(SD2_G, HIGH);
}
void Digit2_four()
{
  digitalWrite(SD2_A, LOW);
  digitalWrite(SD2_B, HIGH);
  digitalWrite(SD2_C, HIGH);
  digitalWrite(SD2_D, LOW);
  digitalWrite(SD2_E, LOW);
  digitalWrite(SD2_F, HIGH);
  digitalWrite(SD2_G, HIGH);
}
void Digit2_five()
{
  digitalWrite(SD2_A, HIGH);
  digitalWrite(SD2_B, LOW);
  digitalWrite(SD2_C, HIGH);
  digitalWrite(SD2_D, HIGH);
  digitalWrite(SD2_E, LOW);
  digitalWrite(SD2_F, HIGH);
  digitalWrite(SD2_G, HIGH);
}
void Digit2_six()
{
  digitalWrite(SD2_A, HIGH);
  digitalWrite(SD2_B, LOW);
  digitalWrite(SD2_C, HIGH);
  digitalWrite(SD2_D, HIGH);
  digitalWrite(SD2_E, HIGH);
  digitalWrite(SD2_F, HIGH);
  digitalWrite(SD2_G, HIGH);
}
void Digit2_seven()
{
  digitalWrite(SD2_A, HIGH);
  digitalWrite(SD2_B, HIGH);
  digitalWrite(SD2_C, HIGH);
  digitalWrite(SD2_D, LOW);
  digitalWrite(SD2_E, LOW);
  digitalWrite(SD2_F, LOW);
  digitalWrite(SD2_G, LOW);
}
void Digit2_eight()
{
  digitalWrite(SD2_A, HIGH);
  digitalWrite(SD2_B, HIGH);
  digitalWrite(SD2_C, HIGH);
  digitalWrite(SD2_D, HIGH);
  digitalWrite(SD2_E, HIGH);
  digitalWrite(SD2_F, HIGH);
  digitalWrite(SD2_G, HIGH);
}
void Digit2_nine()
{
  digitalWrite(SD2_A, HIGH);
  digitalWrite(SD2_B, HIGH);
  digitalWrite(SD2_C, HIGH);
  digitalWrite(SD2_D, HIGH);
  digitalWrite(SD2_E, LOW);
  digitalWrite(SD2_F, HIGH);
  digitalWrite(SD2_G, HIGH);
}
// Digit3 seven segment display functions
void Digit3_zero()
{
  digitalWrite(SD3_A, HIGH);
  digitalWrite(SD3_B, HIGH);
  digitalWrite(SD3_C, HIGH);
  digitalWrite(SD3_D, HIGH);
  digitalWrite(SD3_E, HIGH);
  digitalWrite(SD3_F, HIGH);
  digitalWrite(SD3_G, LOW);
}
void Digit3_one()
{
  digitalWrite(SD3_A, LOW);
  digitalWrite(SD3_B, HIGH);
  digitalWrite(SD3_C, HIGH);
  digitalWrite(SD3_D, LOW);
  digitalWrite(SD3_E, LOW);
  digitalWrite(SD3_F, LOW);
  digitalWrite(SD3_G, LOW);
}
void Digit3_two()
{
  digitalWrite(SD3_A, HIGH);
  digitalWrite(SD3_B, HIGH);
  digitalWrite(SD3_C, LOW);
  digitalWrite(SD3_D, HIGH);
  digitalWrite(SD3_E, HIGH);
  digitalWrite(SD3_F, LOW);
  digitalWrite(SD3_G, HIGH);
}
void Digit3_three()
{
  digitalWrite(SD3_A, HIGH);
  digitalWrite(SD3_B, HIGH);
  digitalWrite(SD3_C, HIGH);
  digitalWrite(SD3_D, HIGH);
  digitalWrite(SD3_E, LOW);
  digitalWrite(SD3_F, LOW);
  digitalWrite(SD3_G, HIGH);
}
void Digit3_four()
{
  digitalWrite(SD3_A, LOW);
  digitalWrite(SD3_B, HIGH);
  digitalWrite(SD3_C, HIGH);
  digitalWrite(SD3_D, LOW);
  digitalWrite(SD3_E, LOW);
  digitalWrite(SD3_F, HIGH);
  digitalWrite(SD3_G, HIGH);
}
void Digit3_five()
{
  digitalWrite(SD3_A, HIGH);
  digitalWrite(SD3_B, LOW);
  digitalWrite(SD3_C, HIGH);
  digitalWrite(SD3_D, HIGH);
  digitalWrite(SD3_E, LOW);
  digitalWrite(SD3_F, HIGH);
  digitalWrite(SD3_G, HIGH);
}
void Digit3_six()
{
  digitalWrite(SD3_A, HIGH);
  digitalWrite(SD3_B, LOW);
  digitalWrite(SD3_C, HIGH);
  digitalWrite(SD3_D, HIGH);
  digitalWrite(SD3_E, HIGH);
  digitalWrite(SD3_F, HIGH);
  digitalWrite(SD3_G, HIGH);
}
void Digit3_seven()
{
  digitalWrite(SD3_A, HIGH);
  digitalWrite(SD3_B, HIGH);
  digitalWrite(SD3_C, HIGH);
  digitalWrite(SD3_D, LOW);
  digitalWrite(SD3_E, LOW);
  digitalWrite(SD3_F, LOW);
  digitalWrite(SD3_G, LOW);
}
void Digit3_eight()
{
  digitalWrite(SD3_A, HIGH);
  digitalWrite(SD3_B, HIGH);
  digitalWrite(SD3_C, HIGH);
  digitalWrite(SD3_D, HIGH);
  digitalWrite(SD3_E, HIGH);
  digitalWrite(SD3_F, HIGH);
  digitalWrite(SD3_G, HIGH);
}
void Digit3_nine()
{
  digitalWrite(SD3_A, HIGH);
  digitalWrite(SD3_B, HIGH);
  digitalWrite(SD3_C, HIGH);
  digitalWrite(SD3_D, HIGH);
  digitalWrite(SD3_E, LOW);
  digitalWrite(SD3_F, HIGH);
  digitalWrite(SD3_G, HIGH);
}
//3
void Digit1_zero()
{
  digitalWrite(SD1_A, HIGH);
  digitalWrite(SD1_B, HIGH);
  digitalWrite(SD1_C, HIGH);
  digitalWrite(SD1_D, HIGH);
  digitalWrite(SD1_E, HIGH);
  digitalWrite(SD1_F, HIGH);
  digitalWrite(SD1_G, LOW);
}
void Digit1_one()
{
  digitalWrite(SD1_A, LOW);
  digitalWrite(SD1_B, HIGH);
  digitalWrite(SD1_C, HIGH);
  digitalWrite(SD1_D, LOW);
  digitalWrite(SD1_E, LOW);
  digitalWrite(SD1_F, LOW);
  digitalWrite(SD1_G, LOW);
}
void Digit1_two()
{
  digitalWrite(SD1_A, HIGH);
  digitalWrite(SD1_B, HIGH);
  digitalWrite(SD1_C, LOW);
  digitalWrite(SD1_D, HIGH);
  digitalWrite(SD1_E, HIGH);
  digitalWrite(SD1_F, LOW);
  digitalWrite(SD1_G, HIGH);
}
void Digit1_three()
{
  digitalWrite(SD1_A, HIGH);
  digitalWrite(SD1_B, HIGH);
  digitalWrite(SD1_C, HIGH);
  digitalWrite(SD1_D, HIGH);
  digitalWrite(SD1_E, LOW);
  digitalWrite(SD1_F, LOW);
  digitalWrite(SD1_G, HIGH);
}
void Digit1_four()
{
  digitalWrite(SD1_A, LOW);
  digitalWrite(SD1_B, HIGH);
  digitalWrite(SD1_C, HIGH);
  digitalWrite(SD1_D, LOW);
  digitalWrite(SD1_E, LOW);
  digitalWrite(SD1_F, HIGH);
  digitalWrite(SD1_G, HIGH);
}
void Digit1_five()
{
  digitalWrite(SD1_A, HIGH);
  digitalWrite(SD1_B, LOW);
  digitalWrite(SD1_C, HIGH);
  digitalWrite(SD1_D, HIGH);
  digitalWrite(SD1_E, LOW);
  digitalWrite(SD1_F, HIGH);
  digitalWrite(SD1_G, HIGH);
}
void Digit1_six()
{
  digitalWrite(SD1_A, HIGH);
  digitalWrite(SD1_B, LOW);
  digitalWrite(SD1_C, HIGH);
  digitalWrite(SD1_D, HIGH);
  digitalWrite(SD1_E, HIGH);
  digitalWrite(SD1_F, HIGH);
  digitalWrite(SD1_G, HIGH);
}
void Digit1_seven()
{
  digitalWrite(SD1_A, HIGH);
  digitalWrite(SD1_B, HIGH);
  digitalWrite(SD1_C, HIGH);
  digitalWrite(SD1_D, LOW);
  digitalWrite(SD1_E, LOW);
  digitalWrite(SD1_F, LOW);
  digitalWrite(SD1_G, LOW);
}
void Digit1_eight()
{
  digitalWrite(SD1_A, HIGH);
  digitalWrite(SD1_B, HIGH);
  digitalWrite(SD1_C, HIGH);
  digitalWrite(SD1_D, HIGH);
  digitalWrite(SD1_E, HIGH);
  digitalWrite(SD1_F, HIGH);
  digitalWrite(SD1_G, HIGH);
}
void Digit1_nine()
{
  digitalWrite(SD1_A, HIGH);
  digitalWrite(SD1_B, HIGH);
  digitalWrite(SD1_C, HIGH);
  digitalWrite(SD1_D, HIGH);
  digitalWrite(SD1_E, LOW);
  digitalWrite(SD1_F, HIGH);
  digitalWrite(SD1_G, HIGH);
}
// void setup area
void setup() {
  Serial.begin(9600);
  pinMode(POT, INPUT); // set A0 as analog input
  for (int i = 0; i < sizeof(LEDS); i++)
  {
    pinMode(LEDS[i], OUTPUT);
  }

  for (int k = 0; k < sizeof(sevensegment); k++)
  {
    pinMode(sevensegment[k], OUTPUT);
  }
  // pinMode(LED_10, OUTPUT);
}
//void loop area
void loop()
{
  int sensorValue = analogRead(POT); // 0 - 1023

  
  int switchnum = map(sensorValue, POT_MIN, POT_MAX, MIN_LIMIT, MAX_LIMIT);
  switchnum = switchnum + 100;
  int lednum = map(sensorValue, 0, 1023, 0, 255);
  
 
    for (int a = 1; a < sizeof(LEDS); a++)
    {
      if (a < lednum/22.5)
      {
        if(a == 1 ) 
        {
            analogWrite(LEDS[a], 25.5);
        }
        if(a == 2) // 156 - 160
        {
            analogWrite(LEDS[a], 51);// 150 - 155 
        }
        if(a == 3) // 161 - 165
        {
            analogWrite(LEDS[a], 76.5);
        }
        if(a == 4) // 166 - 170
        {
            analogWrite(LEDS[a], 102);
        }
        if(a == 5) // 171 - 175
        {
            analogWrite(LEDS[a], 127.5);
        }
        if(a == 6) // 176 - 180
        {
            analogWrite(LEDS[a], 153);
        }
        if(a == 7) // 181 - 185
        {
            analogWrite(LEDS[a], 178.5);
        }
        if(a == 8) // 186 - 190
        {
            analogWrite(LEDS[a], 204);
        }
        if(a == 9) // 191 - 195
        {
            analogWrite(LEDS[a], 229.5);
        }
        if(a == 10) // 196 - 199
        {
            analogWrite(LEDS[a], 255);
        }
      }

      else
      
      {
        analogWrite(LEDS[a], 0);
      }
    }
 

  switch (switchnum)
  {
    case 150:
      Digit1_one();
      Digit2_five(); 
      Digit3_zero();
      break;
    case 151:
      Digit1_one();
      Digit2_five();
      Digit3_one();
      break;
    case 152:
      Digit1_one();
      Digit2_five();
      Digit3_two();
      break;
    case 153:
    Digit1_one();
      Digit2_five();
      Digit3_three();
      break;
    case 154:
    Digit1_one();
      Digit2_five();
      Digit3_four();
      break;
    case 155:
    Digit1_one();
      Digit2_five();
      Digit3_five();
      break;
    case 156:
    Digit1_one();
      Digit2_five();
      Digit3_six();
      break;
    case 157:
    Digit1_one();
      Digit2_five();
      Digit3_seven();
      break;
    case 158:
    Digit1_one();
      Digit2_five();
      Digit3_eight();
      break;
    case 159:
    Digit1_one();
      Digit2_five();
      Digit3_nine();
      break;
    case 160:
    Digit1_one();
      Digit2_six();
      Digit3_zero();
      break;
    case 161:
    Digit1_one();
      Digit2_six();
      Digit3_one();
      break;
    case 162:
    Digit1_one();
      Digit2_six();
      Digit3_two();
      break;
    case 163:
  Digit1_one();
      Digit2_six();
      Digit3_three();
      break;
    case 164:
    Digit1_one();
      Digit2_six();
      Digit3_four();
      break;
    case 165:
    Digit1_one();
      Digit2_six();
      Digit3_five();
      break;
    case 166:
    Digit1_one();
      Digit2_six();
      Digit3_six();
      break;
    case 167:
    Digit1_one();
      Digit2_six();
      Digit3_seven();
      break;
    case 168:
    Digit1_one();
      Digit2_six();
      Digit3_eight();
      break;
    case 169:
   Digit1_one();
      Digit2_six();
      Digit3_nine();
      break;
    case 170:
    Digit1_one();
      Digit2_seven();
      Digit3_zero();
      break;
    case 171:
    Digit1_one();
      Digit2_seven();
      Digit3_one();
      break;
    case 172:
      Digit1_one();
      Digit2_seven();
      Digit3_two();
      break;
     case 173:
      Digit1_one();
      Digit2_seven();
      Digit3_three();
      break;
    case 174:
    Digit1_one();
      Digit2_seven();
      Digit3_four();
      break;
    case 175:
      Digit1_one();
      Digit2_seven();
      Digit3_five();
      break;
   case 176:
      Digit1_one();
      Digit2_seven();
      Digit3_six();
      break;
   case 177:
      Digit1_one();
      Digit2_seven();
      Digit3_seven();
      break;
   case 178:
     Digit1_one();
      Digit2_seven();
      Digit3_eight();
      break;
   case 179:
     Digit1_one();
      Digit2_seven();
      Digit3_nine();
      break;
   case 180:
      Digit1_one();
      Digit2_eight();
      Digit3_zero();
      break;
  case 181:
      Digit1_one();
      Digit2_eight();
      Digit3_one();
      break;
  case 182:
     Digit1_one();
      Digit2_eight();
      Digit3_two();
      break;
  case 183:
      Digit1_one();
      Digit2_eight();
      Digit3_three();
      break;
  case 184:
      Digit1_one();
      Digit2_eight();
      Digit3_four();
      break;
  case 185:
   Digit1_one();
      Digit2_eight();
      Digit3_five();
      break;
  case 186:
     Digit1_one();
      Digit2_eight();
      Digit3_six();
      break;
  case 187:
     Digit1_one();
      Digit2_eight();
      Digit3_seven();
      break;
  case 188:
     Digit1_one();
      Digit2_eight();
      Digit3_eight();
      break;
  case 189:
    Digit1_one();
      Digit2_eight();
      Digit3_nine();
      break;
  case 190:
     Digit1_one();
      Digit2_nine();
      Digit3_zero();
      break;
  case 191:
    Digit1_one();
      Digit2_nine();
      Digit3_one();
      break;
  case 192:
  Digit1_one();
      Digit2_nine();
      Digit3_two();
      break;
  case 193:
      Digit1_one();
      Digit2_nine();
      Digit3_three();
      break;
  case 194:
      Digit1_one();
      Digit2_nine();
      Digit3_four();
      break;
  case 195:
     Digit1_one();
      Digit2_nine();
      Digit3_five();
      break;
  case 196:
      Digit1_one();
      Digit2_nine();
      Digit3_six();
      break;
  case 197:
      Digit1_one();
      Digit2_nine();
      Digit3_seven();
      break;
  case 198:
      Digit1_one();
      Digit2_nine();
      Digit3_eight();
      break;
  case 199:
      Digit1_one();
      Digit2_nine();
      Digit3_nine();
      break;




   
  }

}