/*
Segmento A: Pino 34
Segmento B: Pino 35
Segmento C: Pino 32
Segmento D: Pino 33
Segmento E: Pino 25
Segmento F: Pino 26 
Segmento G: Pino 27
Sensor: Pino 21
*/

// Variáveis Globais
#define SEG_A 33
#define SEG_B 25
#define SEG_C 26
#define SEG_D 27
#define SEG_E 14
#define SEG_F 12
#define SEG_G 13
#define Sensor 21
#define LED_ONBOARD 2

int cpf[] = {5,3,7,0,1,8,2,0,8,6,9};
int i = 0;


void setup()
{ //Direções de Pinos

  pinMode(Sensor,INPUT);
  pinMode(SEG_A, OUTPUT);
  pinMode(SEG_B, OUTPUT);
  pinMode(SEG_C, OUTPUT);
  pinMode(SEG_D, OUTPUT);
  pinMode(SEG_E, OUTPUT);
  pinMode(SEG_F, OUTPUT);
  pinMode(SEG_G, OUTPUT);
  pinMode(LED_ONBOARD, OUTPUT);

  pisca();

}

void pisca() //Função Pisca
{
 for(int cnt=0; cnt<2; cnt++)
 {
  digitalWrite(LED_ONBOARD, HIGH);
  delay(250);
  digitalWrite(LED_ONBOARD, LOW);
  delay(250);
 }
}


void loop()
{
  if(digitalRead(Sensor) == true)
  {
    if(cpf[i] == 0)
    {
      ligaZero();
    }
    if(cpf[i] == 1)
    {
      ligaUm();
    }
    else if(cpf[i] == 2)
    {
      ligaDois();
    }
    else if(cpf[i] == 3)
    {
      ligaTres();
    }
    else if(cpf[i] == 4)
    {
      ligaQuatro();
    }
    else if(cpf[i] == 5)
    {
      ligaCinco();
    }
    else if(cpf[i] == 6)
    {
      ligaSeis();
    }
    else if(cpf[i] == 7)
    {
      ligaSete();
    }
    else if(cpf[i] == 8)
    {
      ligaOito();
    }
    else if(cpf[i] == 9)
    {
      ligaNove();
    }
    if (i == 10)
    {
      i = 0;
    }
    i ++;
    if (i == 10)
    {
      i == 0;
    }
    delay(1000);
  }
}

void ligaZero()
{
  digitalWrite(SEG_A, HIGH);
  digitalWrite(SEG_B, HIGH);
  digitalWrite(SEG_C, HIGH);
  digitalWrite(SEG_D, HIGH);
  digitalWrite(SEG_E, HIGH);
  digitalWrite(SEG_F, HIGH);
  digitalWrite(SEG_G, LOW);
}

void ligaUm()
{
  digitalWrite(SEG_A, HIGH);
  digitalWrite(SEG_B, HIGH);
  digitalWrite(SEG_C, HIGH);
  digitalWrite(SEG_D, LOW);
  digitalWrite(SEG_E, LOW);
  digitalWrite(SEG_F, LOW);
  digitalWrite(SEG_G, LOW);
}
void ligaDois()
{
  digitalWrite(SEG_A, HIGH);
  digitalWrite(SEG_B, HIGH);
  digitalWrite(SEG_C, LOW);
  digitalWrite(SEG_D, HIGH);
  digitalWrite(SEG_E, HIGH);
  digitalWrite(SEG_F, LOW);
  digitalWrite(SEG_G, HIGH);
}
void ligaTres()
{
  digitalWrite(SEG_A, HIGH);
  digitalWrite(SEG_B, HIGH);
  digitalWrite(SEG_C, HIGH);
  digitalWrite(SEG_D, HIGH);
  digitalWrite(SEG_E, LOW);
  digitalWrite(SEG_F, LOW);
  digitalWrite(SEG_G, HIGH);
} 
void ligaQuatro()
{
  digitalWrite(SEG_A, LOW);
  digitalWrite(SEG_B, HIGH);
  digitalWrite(SEG_C, HIGH);
  digitalWrite(SEG_D, LOW);
  digitalWrite(SEG_E, LOW);
  digitalWrite(SEG_F, HIGH);
  digitalWrite(SEG_G, HIGH);
}
void ligaCinco()
{
  digitalWrite(SEG_A, HIGH);
  digitalWrite(SEG_B, LOW);
  digitalWrite(SEG_C, HIGH);
  digitalWrite(SEG_D, HIGH);
  digitalWrite(SEG_E, LOW);
  digitalWrite(SEG_F, HIGH);
  digitalWrite(SEG_G, HIGH);
}
void ligaSeis()
{
  digitalWrite(SEG_A, HIGH);
  digitalWrite(SEG_B, LOW);
  digitalWrite(SEG_C, HIGH);
  digitalWrite(SEG_D, HIGH);
  digitalWrite(SEG_E, HIGH);
  digitalWrite(SEG_F, HIGH);
  digitalWrite(SEG_G, HIGH);
}
void ligaSete()
{
  digitalWrite(SEG_A, HIGH);
  digitalWrite(SEG_B, HIGH);
  digitalWrite(SEG_C, HIGH);
  digitalWrite(SEG_D, LOW);
  digitalWrite(SEG_E, LOW);
  digitalWrite(SEG_F, HIGH);
  digitalWrite(SEG_G, LOW);
}
void ligaOito()
{
  digitalWrite(SEG_A, HIGH);
  digitalWrite(SEG_B, HIGH);
  digitalWrite(SEG_C, HIGH);
  digitalWrite(SEG_D, HIGH);
  digitalWrite(SEG_E, HIGH);
  digitalWrite(SEG_F, HIGH);
  digitalWrite(SEG_G, HIGH);
}
void ligaNove()
{
  digitalWrite(SEG_A, HIGH);
  digitalWrite(SEG_B, HIGH);
  digitalWrite(SEG_C, HIGH);
  digitalWrite(SEG_D, HIGH);
  digitalWrite(SEG_E, LOW);
  digitalWrite(SEG_F, HIGH);
  digitalWrite(SEG_G, HIGH);
}