Mbed based laser tag system using IR LEDs and receivers

Dependencies:   mbed fwdcrc16library PinDetect TextLCD

This project was the result of an embedded systems design course held in 2013.

Revision:
5:6e6ab7e5074e
Parent:
4:7294c20b1025
--- a/main.cpp	Fri Mar 22 17:59:26 2013 +0000
+++ b/main.cpp	Thu Aug 15 18:48:47 2019 +0000
@@ -1,9 +1,16 @@
+//////////////////////////////////////////
+//Embedded Systems Design Final Project //
+//Robert Michael Swan                   //
+//March 21, 2013                        //
+//                                      //
+//Compiled Code Size: 17.7KB            //
+//////////////////////////////////////////
+//Libraries Used
 #include "mbed.h"
 #include "TextLCD.h"
 #include "PinDetect.h"
 #include "crc16.h"
-
- 
+//Peripherals 
 PinDetect  sw2(P0_11); //switch2 debounced input
 PinDetect  sw3(P0_10); //switch3 debounced input
 TextLCD lcd(P1_15, P1_16, P1_19, P1_20, P1_21, P1_22); // rs, e, d4-d7 led pins:4,6,11-14
@@ -13,12 +20,13 @@
 DigitalOut led2(P0_23); //on-board led ds2
 Serial IR(P1_27,P1_26); //IR transmitter and receiver output and input control P1_27 controls IR diode, P1_26 controls IR reciever
 PwmOut Square_Gen(P1_25);       //square wave generator for IR led
+//Timers
 Timeout stats;   //used for displaying text for limited periods of time
 Timeout shot_time; //used to ensure shots take place in a brief period of time
 Timeout flash;  //used to flash leds and backlight when shooting or tagging
 Timer timer;    //used as seconds for reset timer       
 Ticker clock_tick;    //used with timer for minutes of reset timer
-
+//Required global variables
 unsigned mins = 0;   //global variable for minutes in game, since ticker interrupt cannot attach functions that have parameters
 bool btn2 = false;  //global variable for sw2, since the PinDetect interrupt cannot attach functions that have parameters
 bool btn3 = false;  //global variable for sw3, since the PinDetect interrupt cannot attach functions that have parameters
@@ -28,6 +36,7 @@
 char id_rx[15];         //global variable for received ID. Required to use serial interrupt correctly
 unsigned id_pos = 0;    //global variable for recieved ID array location. Also required for serial interrupt.
 
+//Functions
 /*Minute Interrupt
     Intended to be called every minute to increment the minute counter.
     Also resets the seconds timer as it reaches 60 seconds (assuming it is called at timer.start();)
@@ -56,9 +65,6 @@
 void shot_check()
 {
     id_pos = 0;     //resets current id
-    //sets 15th byte of array to NULL
-    //id_rx[14] = NULL;   //if this byte is changed from NULL, it will signify that the player has been successfully tagged
-    //LB = 0; //ensure backlight is back off if it was turned on earlier
 }
 
 /*Serial Callback interrupt
@@ -85,7 +91,7 @@
     {
         id_pos = 0; //ensures no array overflows
         shot_time.detach(); //ensures no further action upon array until next time tagged
-        tagged = true;
+        tagged = true;  //changes tagged flag such that the main code will trigger after an ID is fully received
         return;
     }
     id_pos ++;  //increment to next array position for id
@@ -111,6 +117,11 @@
     
 }
 
+/*Statistics Display Timeout
+    Sets display "done" flag to true
+    Intended to be used with timeout interrupt and statistics function to jump out of function
+    if it has been 5 seconds.
+*/
 void finish_disp ()
 {
     done = true;
@@ -119,7 +130,7 @@
 
 /*Error Routine.
     Displays "ERROR" on LCD screen and flashes leds
-    when called for an indefinite period of time
+    for an indefinite period of time.
 */
 void error_custom ()
 {
@@ -199,6 +210,7 @@
     
     }
 }
+
 /*Character Selection
     Used with setup() function in order to pick a character A-Z and number 0-9
     for use as part of user id and/or team. Passed a 0 if selecting team letter (A-Z),
@@ -477,9 +489,6 @@
     btn2 = false;       //reset button values
     btn3 = false;
     setup(id);      //setup player id and team, passing function the id array
-    /*lcd.cls();
-    lcd.printf("Starting\nin 3 sec");
-    wait(3);*/
     taggable = true;
     LB = 0; //turn off lcd screen, backlight, and leds to save power during game
     LP = 0;
@@ -532,4 +541,4 @@
         }
         wait(0.01);
     }
-}
+}
\ No newline at end of file