// Pines De Salida Para Formar Numero En Display
int pines[7] = {22, 2, 3, 4, 5, 15, 16};
//Estado De Pines Para Formar Cada Numero 0 - 9
byte displaySieteSeg[10][7] = {
{ 1,1,1,1,1,1,0}, //DIGITO 0
{ 0,1,1,0,0,0,0}, //DIGITO 1
{ 1,1,0,1,1,0,1}, //DIGITO 2
{ 1,1,1,1,0,0,1}, //DIGITO 3
{ 0,1,1,0,0,1,1}, //DIGITO 4
{ 1,0,1,1,0,1,1}, //DIGITO 5
{ 1,0,1,1,1,1,1}, //DIGITO 6
{ 1,1,1,0,0,0,0}, //DIGITO 7
{ 1,1,1,1,1,1,1}, //DIGITO 8
{ 1,1,1,1,0,1,1}, //DIGITO 9
};
int numero = 0;
int boton = 13;
void setup(){
Serial.begin(115200);
for(int i=0; i<7; i++)
pinMode(pines[i], OUTPUT);
pinMode(boton, INPUT_PULLDOWN);
// Inicializa Display Con El Numero 0
for(int i=0; i<10; i++){
formaNumero(i);
delay(300);
}
formaNumero(0);
randomSeed(analogRead(34));
}
void loop(){
int estadoBoton = digitalRead(boton);
delay(300);
if(estadoBoton == HIGH){
numero = random(1,7);//Numero Generado Aleatoriamente
Serial.print("Numero:");
Serial.println(numero);
formaNumero(numero);
}
}
void formaNumero(int digito){
int pin = 0;
for (int contadorSegmentos = 0; contadorSegmentos < 7; ++contadorSegmentos){
digitalWrite(pines[pin], !displaySieteSeg[digito][contadorSegmentos]);
++pin;
}
}