You should check the interrupt - http://arduino.cc/en/Reference/AttachInterrupt -
a simple example with the built in LED as light
int pin = 13;
volatile int counter = 0;
void setup()
{
pinMode(pin, OUTPUT);
attachInterrupt(0, irq, FALLING); // HIGH -> LOW
}
void loop()
{
if (counter == 4)
{
digitalWrite(pin, HIGH);
}
if (counter >10)
{
digitalWrite(pin, LOW);
counter = 0;
}
}
void blink()
{
counter++;
}