Laser Tag Code Version 0.89 - How it works

At a high level, there are three things that you need the code to do in order to play laser tag:

  1. Send Tags
  2. Receive Tags
  3. Telegraph your actions with lights and sounds

So let's talk about the first part. The first thing that needs to happen, is a person presses a button. That sends electricity to a pin, which the arduino can detect. That triggers the arduino to send infrared light (which is turned on and off 38,000 times a second) out of an infrared LED for a set amount of time based on the tag you want to send. There is also a sound, so you know you sent a tag.

The next thing that happens, is someone else's device receives the tag. The sensors on the arduino can detect infrared light, but only if it is turned on and off 38,000 times a second, which is called pulsing it at 38 kHz. If the infrared receiver detects light, it sends a signal to one of the arduino's pins. The arduino then times how long the signal is sent. Based on how long the receiver is hit, the arduino knows which type of tag was sent. The arduino can then take the appropriate action, like flashing the lights, making a sound, and adding or subtracting health. 

You can get tagged up to a certain number of times before you are out. The number of times you can be tagged before you are out is called health. When you run out of health, the lights turn off, and you can no longer send tags. You start with 5 health, and you have a maximum of 6 health. If you have 6 health, your RGB LEDs (the ones on your head and your device) turn blue. If you have 5 health, your RGB LEDs are green. As your health goes down, the RGB LEDs slowly change color from green to red. When you run out of health, your RGB LEDs turn off. 

In version 0.89 of the code, there are currently 3 classes. When you press the "tag button," every class will send a regular tag out of the infrared LED. This tag deals one damage to whomever it hits. However, each class has a different ability, which you activate by pressing the ability button.

Buttons

If you are a healer, which is what the tutorial has the device set to, when you press the ability button, you send a tag that heals the other person for 1. If you get hit by this ability, your RGB LEDs flash blue, and you regain one health. 

If you are a soldier, when you press the ability button, you send three tags in a row instead of one and take one damage. 

You switch classes by connecting the pin shown below to either power or ground. In the tutorial, you connect it to power, to the five volt power line. That makes you the "medic" class, which can send tags to heal your allies. The pin you want to connect things to is shown below.

 

However, if you connect the that pin to ground, you then become the "soldier" class. To do this, unplug the end of the wire from the power (where the yellow arrow is below) and plug that end next to the black wire that is connected to ground (where the green arrow is pointing to). You should keep the wire connected where the grey arrow is.

changing classes

After making that change, you will need to reset your arduino, either by pushing the reset button or unplugging in (you'll need to do that every time you change classes). And voila! You now are playing as a different class!

If you want to learn more about the software that lets you program your arduino, I'd suggest Arduino's Tutorials, particularly the ones about setting up and using their online programming software

If you want to download the code and look at it yourself, you can find it here


Newer Post


Leave a comment

Please note, comments must be approved before they are published