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

Committer:
IonSystems
Date:
Thu Nov 06 18:31:50 2014 +0000
Revision:
5:644bca33c1ca
Child:
6:e64796f1f384
This is what is left after Euan took over. The binary file has been halfed i.e most of the code I made has been removed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IonSystems 5:644bca33c1ca 1 Colour readColourSensor(){
IonSystems 5:644bca33c1ca 2 rgb_sensor.getAllColors(rgb_readings);
IonSystems 5:644bca33c1ca 3 Colour colour;
IonSystems 5:644bca33c1ca 4 double redd = (rgb_readings[1] /gMax) * 255;
IonSystems 5:644bca33c1ca 5 double greend = (rgb_readings[2] /bMax) * 255;
IonSystems 5:644bca33c1ca 6 double blued = (rgb_readings[0] /rMax) * 255;
IonSystems 5:644bca33c1ca 7
IonSystems 5:644bca33c1ca 8 int red = redd;
IonSystems 5:644bca33c1ca 9 int green = greend;
IonSystems 5:644bca33c1ca 10 int blue = blued;
IonSystems 5:644bca33c1ca 11 colourDataAcquired = true;
IonSystems 5:644bca33c1ca 12 lcd->cls(); // clear display
IonSystems 5:644bca33c1ca 13 lcd->locate(0,0);
IonSystems 5:644bca33c1ca 14 lcd->printf("R:%d G:%d B:%d",red,green,blue);
IonSystems 5:644bca33c1ca 15
IonSystems 5:644bca33c1ca 16 lcd->locate(1,0);
IonSystems 5:644bca33c1ca 17 if(red > 55){
IonSystems 5:644bca33c1ca 18 lcd->printf("RED");
IonSystems 5:644bca33c1ca 19 }
IonSystems 5:644bca33c1ca 20 if(green > 55){
IonSystems 5:644bca33c1ca 21 lcd->printf("GREEN");
IonSystems 5:644bca33c1ca 22 }
IonSystems 5:644bca33c1ca 23 if(red < 30 && green > 30 && blue > 30){
IonSystems 5:644bca33c1ca 24 lcd->printf("BLUE");
IonSystems 5:644bca33c1ca 25 }
IonSystems 5:644bca33c1ca 26
IonSystems 5:644bca33c1ca 27 bool redWithinThreshold[3] = {0,0,0};
IonSystems 5:644bca33c1ca 28 bool greenWithinThreshold[3]= {0,0,0};
IonSystems 5:644bca33c1ca 29 bool blueWithinThreshold[3]= {0,0,0};
IonSystems 5:644bca33c1ca 30 //Set red Thresholds
IonSystems 5:644bca33c1ca 31 redWithinThreshold[0] = (red >= redLT[0]) && (red <= redUT[0]);
IonSystems 5:644bca33c1ca 32 greenWithinThreshold[0] = (green >= redLT[1]) && (green <= redUT[1]);
IonSystems 5:644bca33c1ca 33 blueWithinThreshold[0] = (blue >= redLT[2]) && (blue <= redUT[2]);
IonSystems 5:644bca33c1ca 34 //Set green Thresholds
IonSystems 5:644bca33c1ca 35 redWithinThreshold[1] = (red >= greenLT[0]) && (red <= greenUT[0]);
IonSystems 5:644bca33c1ca 36 greenWithinThreshold[1] = (green >= greenLT[1]) && (green <= greenUT[1]);
IonSystems 5:644bca33c1ca 37 blueWithinThreshold[1] = (blue >= greenLT[2]) && (blue <= greenUT[2]);
IonSystems 5:644bca33c1ca 38 //Set blue Thresholds
IonSystems 5:644bca33c1ca 39 redWithinThreshold[2] = (red >= blueLT[0]) && (red <= blueUT[0]);
IonSystems 5:644bca33c1ca 40 greenWithinThreshold[2] = (green >= blueLT[1]) && (green <= blueUT[1]);
IonSystems 5:644bca33c1ca 41 blueWithinThreshold[2] = blue >= blueLT[2] && blue <= blueUT[2];
IonSystems 5:644bca33c1ca 42
IonSystems 5:644bca33c1ca 43 if(redWithinThreshold[0] && greenWithinThreshold[0] && blueWithinThreshold[0]){
IonSystems 5:644bca33c1ca 44 lcd->printf("RED");
IonSystems 5:644bca33c1ca 45 colour = RED;
IonSystems 5:644bca33c1ca 46 }
IonSystems 5:644bca33c1ca 47 else if(redWithinThreshold[1] && greenWithinThreshold[1] && blueWithinThreshold[1]){
IonSystems 5:644bca33c1ca 48 lcd->printf("GREEN");
IonSystems 5:644bca33c1ca 49 colour = GREEN;
IonSystems 5:644bca33c1ca 50 }
IonSystems 5:644bca33c1ca 51 else if(redWithinThreshold[2] && greenWithinThreshold[2] && blueWithinThreshold[2]){
IonSystems 5:644bca33c1ca 52 lcd->printf("BLUE");
IonSystems 5:644bca33c1ca 53 colour = BLUE;
IonSystems 5:644bca33c1ca 54 }
IonSystems 5:644bca33c1ca 55 else{
IonSystems 5:644bca33c1ca 56 lcd->printf("BIN");
IonSystems 5:644bca33c1ca 57 colour = OTHER;
IonSystems 5:644bca33c1ca 58 }
IonSystems 5:644bca33c1ca 59 return colour;
IonSystems 5:644bca33c1ca 60 }
IonSystems 5:644bca33c1ca 61
IonSystems 5:644bca33c1ca 62 void sendColourSignal(Colour colour){
IonSystems 5:644bca33c1ca 63 switch(colour){
IonSystems 5:644bca33c1ca 64 case RED:
IonSystems 5:644bca33c1ca 65
IonSystems 5:644bca33c1ca 66 break;
IonSystems 5:644bca33c1ca 67 case GREEN:
IonSystems 5:644bca33c1ca 68 break;
IonSystems 5:644bca33c1ca 69 case BLUE:
IonSystems 5:644bca33c1ca 70 break;
IonSystems 5:644bca33c1ca 71 case OTHER:
IonSystems 5:644bca33c1ca 72 break;
IonSystems 5:644bca33c1ca 73 }
IonSystems 5:644bca33c1ca 74 }