Hola este es nuevo código, implementando la
libreria RDB_Timer y la libreria Switch
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <Switch.h>
#include <RBD_Timer.h>
RBD::Timer TiempoRefresh;
const byte IRsensor = 7;
const byte ShotSensor = 7;
int tirosPermitidos=10;
int Faltantes;
int cantidades;
int contador;
int i;
Switch IRsensorPin = Switch(IRsensor, INPUT, HIGH);
Switch ShotSensorPin = Switch(ShotSensor, INPUT, HIGH);
#define LATCH 9 //Serial Output to Shift Register
#define CLOCK 10 //Shift Register Clock Pin
#define DATA 8 //pin 10 connect to DIO
// array to activate particular digit on the 8x7segment module
// it is the common anode of 7 segment
byte POS[4] = {0X70, 0XB0, 0XD0, 0xE0};
//array for decimal number, it is the cathode.
//logic low will activate the particular segment
byte NUM[10] = {0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6,
0xBE, 0xE0, 0xFE, 0xF6 };
void display4x7(byte datapin, byte clockpin, byte latchpin, byte POS, byte NUM)
{
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLOCK, MSBFIRST, POS); // Particular digit position
shiftOut(DATA, CLOCK, MSBFIRST, NUM); // array for decimal number
digitalWrite(LATCH, HIGH);
}
void displayLED(int numero) {
int unidades;
int decimas;
int centesimas;
int milesimas;
unidades = numero/1000;
numero %= 1000;
decimas = numero/100;
numero %= 100;
centesimas = numero/10;
numero %= 10;
milesimas = numero;
display4x7(DATA, CLOCK, LATCH, POS[0], NUM[milesimas]); //digitOne centesimas
display4x7(DATA, CLOCK, LATCH, POS[1], NUM[centesimas]); //digitOne centesimas
display4x7(DATA, CLOCK, LATCH, POS[2], NUM[decimas]); //digitOne decimas
display4x7(DATA, CLOCK, LATCH, POS[3], NUM[unidades]); // digitOne unidades
}
void Actualiza() {
if(TiempoRefresh.onRestart()) {
displayLED(cantidades);
}
}
void Validos() {
int TirosFallidos=0;
int AlarmPer;
IRsensorPin.poll();
ShotSensorPin.poll();
if (IRsensorPin.pushed()) { contador++; }
if (contador == 4 ) { contador = 0; }
if (contador == 3 ) { digitalWrite(13, HIGH); }
if (contador == 0) { digitalWrite(13, LOW); }
cantidades=contador;
if (ShotSensorPin.pushed()) { TirosFallidos++; }
Faltantes = tirosPermitidos - TirosFallidos;
if (Faltantes == 0) {
contador = 0;
AlarmPer = AlarmPer - 1;}
Serial.print(contador);
}
void setup() {
pinMode(LATCH, OUTPUT);
pinMode(CLOCK, OUTPUT);
pinMode(DATA, OUTPUT);
digitalWrite(LATCH, HIGH); //Wake Up Display
TiempoRefresh.setTimeout(4);
TiempoRefresh.restart();
}
void loop() {
Validos();
Actualiza();
}