Documentos de Académico
Documentos de Profesional
Documentos de Cultura
+-----+
+----[PWR]-------------------| USB |--+
| +-----+ |
| GND/RST2 [ ][ ] |
| MOSI2/SCK2 [ ][ ] A5/SCL[ ] |
| 5V/MISO2 [ ][ ] A4/SDA[ ] |
| AREF[ ] |
| GND[ ] |
| [ ]N/C SCK/13[ ] | Libre
| [ ]IOREF MISO/12[ ] | Libre
| [ ]RST MOSI/11[ ]~| Boton2
| [ ]3V3 +---+ 10[ ]~| Boton1
| [ ]5v -| A |- 9[ ]~| boton_start
| [ ]GND -| R |- 8[ ] | Segmento g
| [ ]GND -| D |- |
| [ ]Vin -| U |- 7[ ] | Segmento f
| -| I |- 6[ ]~| Segmento e
Dig1 | [ ]A0 -| N |- 5[ ]~| Segmento d
Dig2 | [ ]A1 -| O |- 4[ ] | Segmento c
Dig3 | [ ]A2 +---+ INT1/3[ ]~| Segmento b
Dig4 | [ ]A3 INT0/2[ ] | Segmento a
Dig5 | [ ]A4/SDA RST SCK MISO TX>1[ ] | Libre
Dig6 | [ ]A5/SCL [ ] [ ] [ ] RX<0[ ] | Libre
| [ ] [ ] [ ] |
| UNO_R3 GND MOSI 5V ____________/
\_______________________/
****************************************************************/
//DEFINICIONES.
#define boton_1 10
#define boton_2 9
#define boton_start 11
//DECLARACION DE VARIABLES.
int retardo = 1; // tiempo que dura encendido cada 7 seg (1 mili segundos)
int t_digito_on = 1;
int t_digito_off = 1;
int estado;
int puntosLocal = 0;
int puntosVisita = 0;
void setup() {
Serial.begin(9600);
for (int i = 0; i < 8; i++) {
pinMode(pinSeg[i], OUTPUT);
}
for (int k = 0; k < 6; k++) {
pinMode(showDig[k], OUTPUT);
}
escribirNumero(0);
estado = ESTADO_STOP;
}
void loop() {
switch (estado) {
case ESTADO_STOP:
updateDisplayTiempo();
//
leerPulsador_start();
estado = ESTADO_START; /// sss_debug
if (pulsador_start != estadoPulsadorAnterior_start) {
if (antirebote(boton_start) == 0) {
estado = ESTADO_START;
}
}
estadoPulsadorAnterior_start = pulsador_start;
break;
case ESTADO_START:
leerPulsador_1();
leerPulsador_2();
if (pulsador_1 != estadoPulsadorAnterior_1) {
if (antirebote(boton_1) == 0) {
}
else
{
if (( millis() - tiempoPulsador1Presionado) > 1000 )
{
// borro contador de local o de visitante
puntosLocal--;
updateLocal();
}
else
{
puntosLocal++;
updateLocal();
}
}
}
estadoPulsadorAnterior_1 = pulsador_1;
if (pulsador_2 != estadoPulsadorAnterior_2) {
if (antirebote(boton_2) == 0) {
// guardo en vaiable tiempoPulsadorPresionado = millis()
tiempoPulsador2Presionado = millis();
}
else
{
}
else
{
puntosVisita++;
updateVisita();
//Serial.println("Sume!!!!");
}
}
}
estadoPulsadorAnterior_2 = pulsador_2;
contarTiempo();
updateDisplayTiempo();
break;
case ESTADO_FIN:
updateDisplayTiempo();
break;
}
}
//FUNCIONES
void escribirNumero(int numero) {
switch (numero) {
case 0:
for (int j = 0; j < 8; j++) {
digitalWrite(pinSeg[j], cero[j]);
}
break;
case 1:
for (int j = 0; j < 8; j++) {
digitalWrite(pinSeg[j], uno[j]);
}
break;
case 2:
for (int j = 0; j < 8; j++) {
digitalWrite(pinSeg[j], dos[j]);
}
break;
case 3:
for (int j = 0; j < 8; j++) {
digitalWrite(pinSeg[j], tres[j]);
}
break;
case 4:
for (int j = 0; j < 8; j++) {
digitalWrite(pinSeg[j], cuatro[j]);
}
break;
case 5:
for (int j = 0; j < 8; j++) {
digitalWrite(pinSeg[j], cinco[j]);
}
break;
case 6:
for (int j = 0; j < 8; j++) {
digitalWrite(pinSeg[j], seis[j]);
}
break;
case 7:
for (int j = 0; j < 8; j++) {
digitalWrite(pinSeg[j], siete[j]);
}
break;
case 8:
for (int j = 0; j < 8; j++) {
digitalWrite(pinSeg[j], ocho[j]);
}
break;
case 9:
for (int j = 0; j < 8; j++) {
digitalWrite(pinSeg[j], nueve[j]);
}
break;
}
}
void contarTiempo() {
tiempoPasado = (millis() - tiempoInicio) / 1000;
tiempoPasado /= 60;
valor[0] = tiempoPasado / 10;
valor[1] = tiempoPasado - (valor[0] * 10);
if (valor[0] == 6) {
estado = ESTADO_FIN;
}
}
void leerPulsador_1() {
pulsador_1 = digitalRead(boton_1);
}
void leerPulsador_2() {
pulsador_2 = digitalRead(boton_2);
}
void leerPulsador_start() {
pulsador_start = digitalRead(boton_start);
}
void updateDisplayTiempo() {
void updateVisita() {
valor[2] = int(puntosVisita / 10);
valor[3] = puntosVisita - (valor[2] * 10);
void updateLocal() {
valor[4] = int(puntosLocal / 10);
valor[5] = puntosLocal - (valor[4] * 10);
do {
estado = digitalRead(pin);
if (estado != estadoAnterior) {
contador = 0;
estadoAnterior = estado;
} else {
contador = contador + 1;
}
delay(1);
} while (contador < tiempoAntirebote);
return estado;
}