Jasmine Karlsson / Mbed 2 deprecated train_rail

Dependencies:   mbed TextLCD

Revision:
20:32ba0a5f2d02
Parent:
18:f5824ba95892
Child:
21:31647d80614f
diff -r 72b14c6cc845 -r 32ba0a5f2d02 main.cpp
--- a/main.cpp	Mon Jun 11 10:55:45 2018 +0000
+++ b/main.cpp	Mon Jun 11 14:50:15 2018 +0000
@@ -2,6 +2,8 @@
 #include "TextLCD.h"
 #include "MCP23017.h"
 #include "Train.h"
+#include "Switch.h"
+#include "Track.h"
 
 #include <ctime>
 
@@ -77,7 +79,7 @@
 void readVoltage();
 bool readDetector(DigitalIn detector);
 bool readSwitch(DigitalIn theSwitch);
-void DCC_send_command(unsigned int address, unsigned int inst, unsigned int repeat_count); //send command
+//void DCC_send_command(unsigned int address, unsigned int inst, unsigned int repeat_count); //send command
 void initialize_mcp();
 
 
@@ -89,9 +91,45 @@
     sw1.fall(&testInterupt);
     inter0.rise(&riseFunction);
     inter1.rise(&riseFunction);*/
-    Train lightRed(DCCaddress_lightRed);
-    Train darkRed(DCCaddress_darkRed);
-    lcd.printf("Start the journey");
+    Train lightRed(DCCaddress_darkRed, DCCinst_step13);
+    //Train darkRed(DCCaddress_darkRed);
+    Switch switch1(DCCaddress_switch,DCCinst_switch1);
+    //Switch switch2(DCCaddress_switch,DCCinst_switch2);
+    Switch switch3(DCCaddress_switch,DCCinst_switch3);
+    Switch switch4(DCCaddress_switch,DCCinst_switch4);
+
+    while(1){
+        if(readSwitch(sw1)){
+        //DCC_send_command(DCCaddress_switch,DCCinst_switch3,10); //Make sure to deactivate 2 right after activating it
+        switch1.switchOn();    
+        //lcd.printf("%d",switch1.switchOn());
+        lcd.printf("Switch 1 on");
+        //switch2.switchOn();  // Need to turn it off immediately!!!
+        switch3.switchOn();
+        switch4.switchOn();
+    
+        }
+        else{
+        //DCC_send_command(DCCaddress_switch,DCCinst_deactive_switch,10);
+        switch1.switchOff();
+        //switch2.switchOff();
+        switch3.switchOff();
+        switch4.switchOff();
+        lcd.printf("Switch 1 off");    
+            
+        }
+            
+        if(readSwitch(sw2)){
+            lightRed.goForward(DCCinst_step13);
+        }
+        else 
+        {
+            lightRed.Stop(DCCinst_stop);
+        }
+    }
+    
+    
+    /*lcd.printf("Start the journey");
     time_t tstart, tend; 
     initialize_mcp();
     int data = mcp->readRegister(0x12);
@@ -153,7 +191,7 @@
              externalLed4 = 0;
              
         }
-    }
+    }*/
 }
 
 /*----------------------------------------------------------------------------
@@ -234,7 +272,7 @@
     mcp->writeRegister(0x0d, (unsigned char )0x00);
 }
 
-
+/*
 void DCC_send_command(unsigned int address, unsigned int inst, unsigned int repeat_count)
 {
     unsigned __int64 command = 0x0000000000000000; // __int64 is the 64-bit integer type
@@ -270,4 +308,5 @@
         }
         i++;
     }
-}
\ No newline at end of file
+}
+*/
\ No newline at end of file