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 portint buttonState = 0; // buttonstate
int respawn = 5000; // respawn time
int laserShot = 1000; // length of shotvoid 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?