@KenF, Actually I am trying to glow three led's at a time among 12 led and I have modified the code for it, please do correct me if I am wrong
int led[12] = {2,3,4,5,6,7,8,9,10,11,12,13}; //declaring pins for 12 LEDS
int pb[12] = {22,23,24,25,26,27,28,29,30,31,32,33}; // declaring pins for 12 ir
int coinboxsensor1 = 34; // push button for starting the program
int coinboxsensor2 = 35;
int lcdons = 36;
int increment = 37;
int decrement = 38;
int reset = 39;
unsigned long gameLength=90000;//games last 30 seconds
unsigned long timePerLed=3000;// allow 2 seconds per light
unsigned int maxPointsPerLed=100;
boolean playing=false;
unsigned long gameStart;
unsigned long ledStart[3];
int currentLed[3];
unsigned long score;
unsigned long timerscore;
int i;
unsigned long timerscore1;
void setup()
{
for(int n=0;n<12;n++)
{
pinMode(led[n], OUTPUT);
pinMode(pb[n], INPUT);
}
pinMode(coinboxsensor1, INPUT);// two sensors for switching the system on
pinMode(coinboxsensor2, INPUT);
pinMode(lcdons, OUTPUT);// switching the seven segment display for score
pinMode(increment, OUTPUT);// incrementing the seven segment display by one
pinMode(decrement, OUTPUT);// decrementing the seven segment display
pinMode(reset, OUTPUT);// resetting the display
Serial.begin(9600);
Serial.print("Press start button to start!");
}
void loop()
{
unsigned long t=millis();
//if not playing start a new game when startButton is pressed
if(playing == false)
{
int a= digitalRead(coinboxsensor1);
int b = digitalRead(coinboxsensor2);
if (a == 1 && b == 1)
{
playing=true;
//wait for button to be released
digitalWrite(lcdons, HIGH);
delay(1000);
digitalWrite(reset, HIGH);
delay(1000);
digitalWrite(reset, LOW);
gameStart=t;
score=0;
startlight();
}
return;
}
//only continue on if we're in the midst of a game
//Check for end of game
if ( (t-gameStart) >= gameLength)
{
endGame();
return;
}
//Check for timeout on current led
for(i = 0; i<3; i++)
{
if( (t - ledStart[i]) > timePerLed)
{
nextLight();
return;
}
}
for(i = 0; i<3; i++)
{
if (digitalRead(pb[currentLed[i]]) == HIGH ) // check for appropriate ir sensor for the pressed led();
{
digitalWrite(increment, HIGH); // incrementing the score board
timerscore = millis();
//evaluate value of this hit based on time taken
nextLight();
//Serial.print("BANG + ");
//Serial.print (LEDvalue);
//Serial.println(" points");
}
}
if(timerscore>=50)
{
digitalWrite(increment, LOW);
}
}
void nextLight()
{
//extinguish current LED
digitalWrite (led[currentLed[i]], LOW);
//pick another
currentLed[i]=random(12);
//and light it.
digitalWrite(led[currentLed[i]], HIGH);
ledStart[i]=millis();
}
void endGame()
{
for(int l = 0; l<3; l++)
{
digitalWrite(lcdons, HIGH);
delay(1000);
digitalWrite(lcdons, LOW);
delay(1000);
}
playing=false;
}
void startlight()
{
for(i = 0; i<3; i++)
{
currentLed[i] = random(12);
digitalWrite(led[currentLed[i]], HIGH);
ledStart[i] = millis();
}
}