Quad RGB sensor with SPI output drive, I2C display interface & analogue inputs / UI for various LED types

Dependencies:   MCP23S17 PCF8574 TextLCD eeprom mbed-dev

Revision:
5:dc77c5967412
Parent:
4:dce5fc58abe9
Child:
6:6346ef2b4638
--- a/main.cpp	Tue Aug 16 15:00:22 2016 +0000
+++ b/main.cpp	Tue Aug 16 15:54:31 2016 +0000
@@ -36,7 +36,7 @@
 //--------------------------------------
 
 
-
+void SelectSensorPort(uint8_t SensorID);
 
 //-------------------------------------------------------------------------------
 //----------- LED's -------------------------------------------------------------
@@ -52,6 +52,12 @@
 DigitalOut RedLed(LED3);
 DigitalOut YellowLed(LED4);
 
+//I2C address selection pins
+DigitalOut I2C_ID_Bit0(p13);
+DigitalOut I2C_ID_Bit1(p14);
+DigitalOut I2C_ID_Bit2(p12);
+DigitalOut I2C_ID_Bit3(p11);
+
 //-------------------------------------------------------------------------------
 
 //-------------------------------------------------------------------------------
@@ -69,7 +75,7 @@
 //-------------------------------------------------------------------------------
 //debug display. Standard display driver set up in 4 bit mode
 //final version uses I2C port
-TextLCD lcd(p14, p16, p17, p18, p19, p20, TextLCD::LCD16x2); // rs, e, d4-d7
+TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD16x2); // rs, e, d4-d7
 
 //set up I2C Communication to LCD
 //I2C i2c_lcd(p9,p10); // SDA, SCL
@@ -112,7 +118,7 @@
 //-------------------------------------------------------------------------------
 //The system looks up the type of LED that is being detected for Each sensor and will fill in the result table & update the associated Output list
 //outputs start at 0 torough to 15
-
+/*
 char Config[32]={   //RGB,    0,  //sensor 0 , uses 3 outputs  - 0,1,2
                     GREEN_YELLOW,   0,  //sensor 0 , uses 3 outputs  - 0,1,2
                     NOTUSED,        2,  //sensor 1
@@ -131,6 +137,26 @@
                     NOTUSED,        15,  //sensor 14
                     NOTUSED,        15,  //sensor 15
                 };
+*/
+char Config[32]={   //RGB,    0,  //sensor 0 , uses 3 outputs  - 0,1,2
+                    STD_RED,        0,  //sensor 0 , uses 3 outputs  - 0,1,2
+                    STD_GREEN,      1,  //sensor 1
+                    STD_RED,        2,  //sensor 2
+                    STD_GREEN,      3,  //sensor 3
+                    STD_RED,        4,  //sensor 4                    
+                    STD_GREEN,      5,  //sensor 5
+                    STD_RED,        6,  //sensor 6
+                    STD_GREEN,      7,  //sensor 7
+                    STD_RED,        8,  //sensor 8
+                    STD_GREEN,      9,  //sensor 9
+                    STD_RED,        10,  //sensor 10
+                    STD_GREEN,      11,  //sensor 11
+                    STD_RED,        12,  //sensor 12
+                    STD_GREEN,      13,  //sensor 13
+                    STD_RED,        14,  //sensor 14
+                    STD_GREEN,      15,  //sensor 15
+                };
+
 
 char LEDState[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //current detected LED states
 
@@ -249,6 +275,9 @@
     Colour NewData;
     char AddrReg[1] = {0};
     char DataReg[5] ={0,0,0,0,0};
+
+
+    SelectSensorPort(SensorNumber);
         
     NewData.White = 0;
     NewData.Red = 0;
@@ -350,6 +379,49 @@
     Hysteresis      = 5;
 }
 
+void SelectSensorPort(uint8_t SensorID)
+{
+  
+    if ( SensorID < 16)
+    {
+        if((SensorID & 0x01) == 0x01)
+        {
+            I2C_ID_Bit0 = 1;
+        }
+        else
+        {   
+            I2C_ID_Bit0 = 0;
+        }
+        
+        if((SensorID & 0x02) == 0x02)
+        {
+            I2C_ID_Bit1 = 1;
+        }
+        else
+        {   
+            I2C_ID_Bit1 = 0;
+        }
+        
+        if((SensorID & 0x04) == 0x04)
+        {
+            I2C_ID_Bit2 = 1;
+        }
+        else
+        {   
+            I2C_ID_Bit2 = 0;
+        } 
+        
+        if((SensorID & 0x08) == 0x08)
+        {
+            I2C_ID_Bit3 = 1;
+        }
+        else
+        {   
+            I2C_ID_Bit3 = 0;
+        }      
+    } 
+}
+
 
 void UpdateDisplay(void)
 {