Using the timer library to torn on an LED and turn off a laser for 5 seconds

Hello all,

Currently I am working on a little box with which you can play laser tag on a smart table.

I am at the point where I want to turn on an LED for 5 seconds, and at the same time turn down the laser for those same 5 seconds. (The you are hit, your LED burns and you can't shoot period).

I use this library: Arduino Playground - HomePage

This is the code I currently have:

// IMPORT
#include "Timer.h"

Timer tlaser;
Timer tled;

// PIN ASSIGNMENT
int resistor = 0; // resistor port.
int button = 2; // button port.
int laser = 4; // lµaser port.
int led = 13; // led port

int buttonState = 0; // buttonstate
int respawn = 5000; // respawn time
int laserShot = 1000; // length of shot

void setup() {

Serial.begin(9600);
pinMode (button, INPUT);
pinMode (laser, OUTPUT);
pinMode (resistor, OUTPUT);
pinMode (led, OUTPUT);

// TIMED FUNCTIONS
tlaser.oscillate(laser, 5000, LOW);
tled.oscillate(led, 5000, HIGH);

}

void loop() {

// read button state and shoot laser on button down
buttonState = digitalRead(button);
if (buttonState == HIGH) {
digitalWrite(laser, HIGH);
} else {
digitalWrite(laser, LOW);
}

// read resistor and set to v.
int v = analogRead(resistor);
// Serial.println( v);

// statement for resistor v.
if ( v > 900 ){
tlaser.update();
tled.update();
//Serial.println("Higher!");
} else {
//Serial.println("Lower!");
digitalWrite (led, LOW);
}
}

However, the LED doesn't go on, and the laser isn't turned down once I hit the resistor with the laser.

Can anyone point me in the right direction or tell me what I'm doing wrong?

Whilst I know nothing about the timer library that you are using I would guess that

  tlaser.oscillate(laser, 5000, LOW);
  tled.oscillate(led, 5000, HIGH);

Would make the LED and the laser turn on and off every 5 seconds but what triggers them to start and stop ?

Unless you are using it for other things I would be inclined to drop the library and do the timing yourself using millis(), then you will know exactly what is going on and it will be easier to insert debugging statements into your program.

Can we assume that the trigger level that you are testing (v > 900) is correct ?

Yes, (v > 900) is the trigger to start the LED and stop the laser, and a 5000 millis timer would stop that.

Do you have a link to a good milli counter tutorial?

Evin:
Do you have a link to a good milli counter tutorial?

Thanks!