Evening all,

So I'm attempting to make an IR based 'tin can alley' rifle game and therefore trying to learn arduino programming at the same time. I'm pretty confident that I can get the IR LED to flash when a button is pressed but what I can't get my head round is how I would write the code so that if the trigger button is continually depressed for any amount of time, it would only ever flash once and only allows the system to loop round again once the trigger has been released? I wrote the code below as a total 'starter for ten' off the button example but I'm highly doubtful it will work. Any help is greatly appreciated!

Cheers

Dan

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
delay(1000); // wait for a second
digitalWrite(ledPin, LOW);
if (buttonState == HIGH);
digitalWrite(ledPin, LOW);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}