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

colourProcessing.h

Committer:
IonSystems
Date:
2014-11-06
Revision:
5:644bca33c1ca
Child:
6:e64796f1f384

File content as of revision 5:644bca33c1ca:

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;
        
        int red = redd;
        int green = greend;
        int blue = blued;  
        colourDataAcquired = true;
        lcd->cls(); // clear display 
        lcd->locate(0,0); 
        lcd->printf("R:%d G:%d B:%d",red,green,blue);
        
        lcd->locate(1,0); 
        if(red > 55){
            lcd->printf("RED");
        }
        if(green > 55){
            lcd->printf("GREEN");
        } 
        if(red < 30 && green > 30 && blue > 30){
            lcd->printf("BLUE");
        }  
        
        bool redWithinThreshold[3] = {0,0,0};
        bool greenWithinThreshold[3]= {0,0,0};
        bool blueWithinThreshold[3]= {0,0,0};
        //Set red Thresholds
        redWithinThreshold[0] = (red >= redLT[0]) && (red <= redUT[0]);
        greenWithinThreshold[0] = (green >= redLT[1]) && (green <= redUT[1]);
        blueWithinThreshold[0] = (blue >= redLT[2]) && (blue <= redUT[2]);
        //Set green Thresholds
        redWithinThreshold[1] = (red >= greenLT[0]) && (red <= greenUT[0]);
        greenWithinThreshold[1] = (green >= greenLT[1]) && (green <= greenUT[1]);
        blueWithinThreshold[1] = (blue >= greenLT[2]) && (blue <= greenUT[2]);
        //Set blue Thresholds
        redWithinThreshold[2] = (red >= blueLT[0]) && (red <= blueUT[0]);
        greenWithinThreshold[2] = (green >= blueLT[1]) && (green <= blueUT[1]);
        blueWithinThreshold[2] = blue >= blueLT[2] && blue <= blueUT[2];
        
        if(redWithinThreshold[0] && greenWithinThreshold[0] && blueWithinThreshold[0]){
            lcd->printf("RED");
            colour = RED;
            }
        else if(redWithinThreshold[1] && greenWithinThreshold[1] && blueWithinThreshold[1]){
            lcd->printf("GREEN");
            colour = GREEN;
            }
        else if(redWithinThreshold[2] && greenWithinThreshold[2] && blueWithinThreshold[2]){
            lcd->printf("BLUE");
            colour = BLUE;
            }
        else{
            lcd->printf("BIN");
            colour = OTHER;
            }    
        return colour;
}

void sendColourSignal(Colour colour){
    switch(colour){
        case RED: 
        
        break;
        case GREEN:
        break;
        case BLUE:
        break;
        case OTHER:
        break;
        }
    }