The MBED firmware used on the Chipin sorter, developed over 12 weeks for a 3rd year university systems project. Chipin is a token sorter, it sorts tokens by colours and dispenses them to order through an online booking system and card reader. This program interfaces with an FPGA, PC and LCD screen to control the sorter. The sorter has an operation mode where it can process orders when a card is entered into the machine. There is also a maintenance mode where the device responds to maintenance instructions such as 'dispense all'. More information at http://www.ionsystems.uk/

Dependencies:   MCP23017 TCS3472_I2C WattBob_TextLCD mbed-rtos mbed

Revision:
13:0661d658d9d1
Parent:
11:06f6e82b40a8
Child:
14:31ba3e56c788
--- a/colourProcessing.h	Mon Nov 17 21:31:42 2014 +0000
+++ b/colourProcessing.h	Thu Nov 20 11:15:47 2014 +0000
@@ -19,12 +19,14 @@
 int blueLT [3]= {25,47,47};
 int blueUT [3]= {28,52,52};*/
 //values for blue backing
-int redLT [3] =     {211,0,0};
-int redUT [3]=      {400,140,200};
-int greenLT [3] =   {141,251,211};
-int greenUT [3]=    {210,400,400};
-int blueLT [3]=     {0,141,150};
-int blueUT [3]=     {140,250,210};
+int redLT [3] =     {300,80,150};
+int redUT [3]=      {400,156,230};
+int greenLT [3] =   {180,356,265};
+int greenUT [3]=    {268,436,345};
+int blueLT [3]=     {89,187,189};
+int blueUT [3]=     {168,267,269};
+int noneLT [3] = {0,0,0};
+int noneUT [3] = {80,80,80};
 
 void initColourSensor(){
     rgb_sensor.enablePowerAndRGBC();
@@ -33,7 +35,7 @@
 
 Colour readColourSensor(){
         rgb_sensor.getAllColors(rgb_readings);
-        Colour colour;
+        
         double redd = (rgb_readings[1] /gMax) * 255;
         double greend = (rgb_readings[2] /bMax) * 255;
         double blued = (rgb_readings[0] /rMax) * 255;
@@ -57,9 +59,9 @@
             lcd->printf("BLUE");
         }*/  
         
-        bool redWithinThreshold[3] = {0,0,0};
-        bool greenWithinThreshold[3]= {0,0,0};
-        bool blueWithinThreshold[3]= {0,0,0};
+        bool redWithinThreshold[4] = {0,0,0,0};
+        bool greenWithinThreshold[4]= {0,0,0,0};
+        bool blueWithinThreshold[4]= {0,0,0,0};
         //Set red Thresholds
         redWithinThreshold[0] = (red >= redLT[0]) && (red <= redUT[0]);
         greenWithinThreshold[0] = (green >= redLT[1]) && (green <= redUT[1]);
@@ -72,36 +74,33 @@
         redWithinThreshold[2] = (red >= blueLT[0]) && (red <= blueUT[0]);
         greenWithinThreshold[2] = (green >= blueLT[1]) && (green <= blueUT[1]);
         blueWithinThreshold[2] = blue >= blueLT[2] && blue <= blueUT[2];
+        //Set none Thresholds
+        redWithinThreshold[3] = (red >= noneLT[0]) && (red <= noneUT[0]);
+        greenWithinThreshold[3] = (green >= noneLT[1]) && (green <= noneUT[1]);
+        blueWithinThreshold[3] = blue >= noneLT[2] && blue <= noneUT[2];
         
         if(redWithinThreshold[0] && greenWithinThreshold[0] && blueWithinThreshold[0]){
             lcd->printf("RED");
-            colour = RED;
+            return RED;
             }
         else if(redWithinThreshold[1] && greenWithinThreshold[1] && blueWithinThreshold[1]){
             lcd->printf("GREEN");
-            colour = GREEN;
+            return GREEN;
             }
         else if(redWithinThreshold[2] && greenWithinThreshold[2] && blueWithinThreshold[2]){
             lcd->printf("BLUE");
-            colour = BLUE;
+            return BLUE;
+            }
+         else if(redWithinThreshold[3] && greenWithinThreshold[3] && blueWithinThreshold[3]){
+            lcd->printf("NONE");
+            return NONE;
             }
         else{
             lcd->printf("BIN");
-            colour = BIN;
+            return BIN;
             }    
-        return colour;
+       
 }
 
-void sendColourSignal(Colour colour){
-    switch(colour){
-        case RED: 
-        
-        break;
-        case GREEN:
-        break;
-        case BLUE:
-        break;
-        case BIN:
-        break;
-        }
-    }
\ No newline at end of file
+
+