Monday, August 23, 2010

Phoenix LTX

Hey look I made a lazer tag gun! It runs on Arduino using the IRremote library.

Send:
void IRsend::sendPHOENIX_LTX(unsigned long data, int nbits) {

enableIROut(36);
//HEAD
mark(PHOENIX_HDR_MARK);
space(PHOENIX_HDR_SPACE);
mark(PHOENIX_HDR_MARK);
int i = 0;
for (i = 0; i < 7; i++) {
if (i % 2 == 0) {
space(PHOENIX_LTX_SPACE);
} else {
mark(PHOENIX_LTX_ZERO_MARK);
}
}
//DATA
if ((data >> 2) & 1 == 1) {
mark(PHOENIX_LTX_ONE_MARK);
} else {
mark(PHOENIX_LTX_ZERO_MARK);
}
space(PHOENIX_LTX_SPACE);
if ((data >> 0) & 1 == 1) {
mark(PHOENIX_LTX_ONE_MARK);
} else {
mark(PHOENIX_LTX_ZERO_MARK);
}
//TAIL
for (i = 0; i < 4; i++) {
if (i % 2 == 0) {
space(PHOENIX_LTX_SPACE);
} else {
mark(PHOENIX_LTX_ZERO_MARK);
}
}
space(PHOENIX_LTX_SPACE);

}

Receive:
long IRrecv::decodePHOENIX_LTX(decode_results *results) {

long data = 0;

int offset = 1;

int i = 0;

//HEAD

if (results->rawlen != 18) {

return ERR;

}

if (!MATCH_MARK(results->rawbuf[offset], PHOENIX_HDR_MARK)) {

return ERR;

}

offset++;

if (!MATCH_SPACE(results->rawbuf[offset], PHOENIX_HDR_SPACE)) {

return ERR;

}

offset++;

if (!MATCH_MARK(results->rawbuf[offset], PHOENIX_HDR_MARK)) {

return ERR;

}

offset++;

for (i = 0; i < 7; i++) {

if (i % 2 == 0) {

if (!MATCH_SPACE(results->rawbuf[offset], 2000)) {

Serial.println(i, DEC);

return ERR;

}



} else {



if (!MATCH_MARK(results->rawbuf[offset], 1000)) {

Serial.println(i, DEC);

return ERR;

}

}

offset++;

}

Serial.println("Data");

//DATA

for (i = 0; i < 3; i++) {

if (MATCH_MARK(results->rawbuf[offset], PHOENIX_LTX_ONE_MARK)) {

data << 1;

data |= 1;

} else if (MATCH_MARK(results->rawbuf[offset], PHOENIX_LTX_ZERO_MARK)) {

data << 1;

data |= 0;

} else {

Serial.println(i, DEC);

return ERR;

}

offset++;

}

Serial.println("Tail");

//TAIL

for (i = 0; i < 2; i++) {

if (!MATCH_SPACE(results->rawbuf[offset], 2000)) {

return ERR;

}

offset++;

if (!MATCH_MARK(results->rawbuf[offset], 1000)) {

return ERR;

}

offset++;

}



// Success

results->bits = 3;

results->value = data;

results->decode_type = PHOENIX_LTX;

return DECODED;

}

Defines:
#define PHOENIX_HDR_MARK 3000
#define PHOENIX_HDR_SPACE 6000
#define PHOENIX_LTX_ONE_MARK 2000
#define PHOENIX_LTX_ZERO_MARK 1000
#define PHOENIX_LTX_SPACE 2000

6 comments:

Andrew Rosenblum said...

How does your gun compare to the ones you can buy for 2 for $60? Why did you make one?

afaucher said...

It was designed to be compatible with them, but primarily to serve as a game hosting station. Those guns support a number of game types that you can only use if you use a Laser Tag Team Ops gun to host, as it has an LCD and a menu. Not only are those guns hard to find, as they stopped making them, hosting is pretty unreliable as any gun that gets turned off or times out prevents everyone from seeing their scores. Hosting a game from a laptop would have neither problem.

Derek R. said...

Hi there!

I was thinking about using an Arduino to pick up the IR signal from these guns and make a functional shield out of a toy lightsaber- with the ignition button acting as the shield activation and with similar mechanics to the guns shield.

Think this mod is possible using your library? Furthermore, do you have any tips on where to start? My programing skills are rudimentary at best...

Thanks! :)

afaucher said...

Derek,

The shield button on the gun interacts with the software on the gun itself. There is no way to interface an external component and have it behave like the gun's own shield unless you pull your gun apart and rewire the shield button.

You would effectively just be moving the shield button into the grip of the physical shield. They would need to be connected by a wire.

John said...

Trying to put this together and having some trouble creating trigger actions. I am working on the hosting station and a couple of grenades. I need help with the triggering and am very new to arduino. Can you give a little assistance?

afaucher said...

John,

Do you have your code somewhere I could take a look? I haven't worked on this in a while but I am happy to look.