Denver / Mbed 2 deprecated denver_train_proj

Dependencies:   mbed TextLCD

Revision:
38:b9aba3715682
Parent:
36:9428c72bdd58
Child:
39:9cce8f2c50b6
--- a/main.cpp	Thu Jun 14 12:56:31 2018 +0000
+++ b/main.cpp	Thu Jun 14 13:12:36 2018 +0000
@@ -7,7 +7,6 @@
 
 using namespace std;
 
-//mbed DCC Model Train Demo
  
 /******PINS AND DECLARATIONS*******/
 
@@ -70,6 +69,8 @@
 
 //------GLOBAL VARS
 
+//......SENSOR POSITION VARS
+
 #define D0 0
 #define D1 1
 #define D2 2
@@ -87,52 +88,23 @@
 #define D21 14
 #define D22 15
 
-
-//.....DCC TRAIN COMMAND VARS
-
-//typical out of box default engine DCC address is 3 (at least for Bachmann trains)
-//Note: A DCC controller can reprogram the address whenever needed
-const unsigned int DCCaddressDR = 0x01; //Address for train 1 DARK-RED
-const unsigned int DCCaddressLR = 0x03; //Address for train 3 LIGHT-RED
-
-//01DCSSSS for speed, D is direction (fwd=1 and rev=0), C is speed(SSSSC) LSB
-const unsigned int DCCinst_forward = 0x68; //forward half speed
-const unsigned int DCCinst_forward_slow = 0x66; //forward half speed
-const unsigned int DCCinst_reverse = 0x48; //reverse half speed
-const unsigned int DCCinst_stop = 0x50;    //stop the train
-
-//100DDDDD for basic headlight functions
-const unsigned int DCC_func_lighton = 0x90; //F0 turns on headlight function
-const unsigned int DCC_func_dimlight = 0x91; //F0 + F1 dims headlight
-
-
-//.....SWITCH COMMAND VARS
-    
-const unsigned int SWBaddress = 0x06; //Address for switch box
-
-//100DDDDD where DDDDD is the switch command and 100 is constant:
-
-//00001(F1 active)-00010(F2 active)-00100(F3 active)-01000(F4 active)
-//Example - 111111 0 00000101 0 10000000 0 10000101 1 - idle
-
-const unsigned int SWBidle = 0x80; //IDLE - Flip last activated SW.
-const unsigned int SWBflip_1 = 0x81; //Flip SW1
-const unsigned int SWBflip_2 = 0x82; //Flip SW2
-const unsigned int SWBflip_3 = 0x84; //Flip SW3
-const unsigned int SWBflip_4 = 0x88; //Flip SW4
-
-//Arrays that will keep track of the position and direction of th trains.
-//[pos_trains] -1 = not in track / any other number = sensor where the train is at (sensors 1-16)
-//[dir_trains] -1 = left / 1 = right
-int pos_trains [2] = {-1,-1};
-int dir_trains [2] = {-1,-1};
-
-
-
-
-
-//**************** FUNCTIONS FOR DENVER TRAIN ****************//
-
+/**
+*
+*Position class.
+*
+*@position - 
+*@previous_cw - 
+*@previous_ccw - 
+*
+*Position(int) - 
+*
+*get_pos() - 
+*get_prev_cw() - 
+*get_ccw() - 
+*add_prev_cw() - 
+*add_ccw() - 
+*
+**/
 class Position{
     private:
         int position; 
@@ -164,6 +136,8 @@
         };
 };
 
+//Creation of all the positions. One for every sensor on the table - Position name(mapping)
+
 Position d0(D0);
 Position d1(D1);
 Position d2(D2);
@@ -181,8 +155,42 @@
 Position d21(D21);
 Position d22(D22);
 
+//Creating a vector with all the positions.
 vector<Position> positions;
 
+
+//.....DCC TRAIN COMMAND VARS
+
+//typical out of box default engine DCC address is 3 (at least for Bachmann trains)
+//Note: A DCC controller can reprogram the address whenever needed
+const unsigned int DCCaddressDR = 0x01; //Address for train 1 DARK-RED
+const unsigned int DCCaddressLR = 0x03; //Address for train 3 LIGHT-RED
+
+//01DCSSSS for speed, D is direction (fwd=1 and rev=0), C is speed(SSSSC) LSB
+const unsigned int DCCinst_forward = 0x68; //forward half speed
+const unsigned int DCCinst_forward_slow = 0x66; //forward half speed
+const unsigned int DCCinst_reverse = 0x48; //reverse half speed
+const unsigned int DCCinst_stop = 0x50;    //stop the train
+
+//100DDDDD for basic headlight functions
+const unsigned int DCC_func_lighton = 0x90; //F0 turns on headlight function
+const unsigned int DCC_func_dimlight = 0x91; //F0 + F1 dims headlight
+
+
+//.....SWITCH COMMAND VARS
+    
+const unsigned int SWBaddress = 0x06; //Address for switch box
+
+//100DDDDD where DDDDD is the switch command and 100 is constant:
+
+//00001(F1 active)-00010(F2 active)-00100(F3 active)-01000(F4 active)
+//Example - 111111 0 00000101 0 10000000 0 10000101 1 - idle
+const unsigned int SWBidle = 0x80; //IDLE - Flip last activated SW.
+const unsigned int SWBflip_1 = 0x81; //Flip SW1
+const unsigned int SWBflip_2 = 0x82; //Flip SW2
+const unsigned int SWBflip_3 = 0x84; //Flip SW3
+const unsigned int SWBflip_4 = 0x88; //Flip SW4
+
 //Starting position and orientation of the trains
 int DR_train_pos = D4;
 bool DR_cw = true;
@@ -191,6 +199,10 @@
 bool LR_cw = true;
 
 
+
+//**************** FUNCTIONS FOR DENVER TRAIN ****************//
+
+
 /**
 *Activates the buzzer for 0.5 seconds.
 **/