Denver / Mbed 2 deprecated denver_train_proj

Dependencies:   mbed TextLCD

Revision:
34:c9ab2a987734
Parent:
33:24ce12dec157
Child:
35:cfcfeccb959e
diff -r 24ce12dec157 -r c9ab2a987734 main.cpp
--- a/main.cpp	Wed Jun 13 12:02:48 2018 +0000
+++ b/main.cpp	Wed Jun 13 13:36:14 2018 +0000
@@ -67,6 +67,23 @@
 
 //------GLOBAL VARS
 
+#define D0 0
+#define D1 1
+#define D2 2
+#define D3 3
+#define D4 4
+#define D5 5
+#define D6 6
+#define D7 7
+#define D8 8
+#define D9 9
+#define D10 10
+#define D11 11
+#define D12 12
+#define D13 13
+#define D21 14
+#define D22 15
+
 
 //.....DCC TRAIN COMMAND VARS
 
@@ -150,6 +167,26 @@
 
 /**
 *
+*/
+
+int get_sensor(unsigned int number,int interrupt){
+    int sensor = -1;
+    
+    for(int i=0; i<8;i++){
+        
+        if(~number & 1<<i){            
+            sensor = i; 
+        }
+    }
+    
+    if(interrupt == 1){
+        sensor+=8; // Sensors caught by interreupt1 are identified from 8 to 15.
+    }
+    return sensor;
+}
+
+/**
+*
 *Method to catch interrupts 0
 *
 **/
@@ -157,12 +194,12 @@
      
      wait_us(2000);
      int sensor_data = mcp->_read(INTCAPA);
+     int sensor = get_sensor(sensor_data,0);
      lcd.cls();
-     lcd.printf("int0 0x%x",sensor_data);
+     lcd.printf("int0 0x%x \n Sensor: %d",sensor_data,sensor);
      
 }
 
-
 /**
 *
 *Method to catch interrupts 1
@@ -172,8 +209,9 @@
     
     wait_us(2000);
      int sensor_data = mcp->_read(INTCAPB);
+     int sensor = get_sensor(sensor_data,1);
      lcd.cls();
-     lcd.printf("int1 0x%x",sensor_data);
+     lcd.printf("int1 0x%x \n Sensor: %d",sensor_data,sensor);
 }
 
 
@@ -399,7 +437,7 @@
             lcd.cls();
             
         }else{
-            DCC_send_command(DCCaddressDR,DCCinst_forward_slow,1); // Forward half speed train addres DARK-RED             
+            DCC_send_command(DCCaddressDR,DCCinst_forward,1); // Forward half speed train addres DARK-RED             
             DCC_send_command(DCCaddressLR,DCCinst_forward,1); // Forward half speed train address LIGHT-RED
         } 
     }