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 20 11:15:47 2014 +0000
Revision:
13:0661d658d9d1
Parent:
11:06f6e82b40a8
Child:
14:31ba3e56c788
Maintenance mode added, still need to do the printouts to the lcd.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IonSystems 6:e64796f1f384 1 #include "mbed.h"
IonSystems 6:e64796f1f384 2 #include "TCS3472_I2C.h"
IonSystems 6:e64796f1f384 3 #include "Colour.h"
IonSystems 11:06f6e82b40a8 4
IonSystems 6:e64796f1f384 5 TCS3472_I2C rgb_sensor(p28,p27); //p28 =sda, p27=scl
IonSystems 6:e64796f1f384 6
IonSystems 6:e64796f1f384 7 int rgb_readings[4];
IonSystems 6:e64796f1f384 8 double rMax = 9244;
IonSystems 6:e64796f1f384 9 double gMax = 3194;
IonSystems 6:e64796f1f384 10 double bMax = 3590;
IonSystems 6:e64796f1f384 11
IonSystems 6:e64796f1f384 12 //thresholds are in the RGB format.
IonSystems 11:06f6e82b40a8 13 /*
IonSystems 11:06f6e82b40a8 14 Values for black casing
IonSystems 6:e64796f1f384 15 int redLT [3] = {79,23,41};
IonSystems 6:e64796f1f384 16 int redUT [3]= {92,28,49};
IonSystems 6:e64796f1f384 17 int greenLT [3] = {46,81,61};
IonSystems 6:e64796f1f384 18 int greenUT [3]= {60,107,81};
IonSystems 6:e64796f1f384 19 int blueLT [3]= {25,47,47};
IonSystems 11:06f6e82b40a8 20 int blueUT [3]= {28,52,52};*/
IonSystems 11:06f6e82b40a8 21 //values for blue backing
IonSystems 13:0661d658d9d1 22 int redLT [3] = {300,80,150};
IonSystems 13:0661d658d9d1 23 int redUT [3]= {400,156,230};
IonSystems 13:0661d658d9d1 24 int greenLT [3] = {180,356,265};
IonSystems 13:0661d658d9d1 25 int greenUT [3]= {268,436,345};
IonSystems 13:0661d658d9d1 26 int blueLT [3]= {89,187,189};
IonSystems 13:0661d658d9d1 27 int blueUT [3]= {168,267,269};
IonSystems 13:0661d658d9d1 28 int noneLT [3] = {0,0,0};
IonSystems 13:0661d658d9d1 29 int noneUT [3] = {80,80,80};
IonSystems 6:e64796f1f384 30
IonSystems 6:e64796f1f384 31 void initColourSensor(){
IonSystems 6:e64796f1f384 32 rgb_sensor.enablePowerAndRGBC();
IonSystems 6:e64796f1f384 33 rgb_sensor.setIntegrationTime(100);
IonSystems 6:e64796f1f384 34 }
IonSystems 6:e64796f1f384 35
IonSystems 5:644bca33c1ca 36 Colour readColourSensor(){
IonSystems 5:644bca33c1ca 37 rgb_sensor.getAllColors(rgb_readings);
IonSystems 13:0661d658d9d1 38
IonSystems 5:644bca33c1ca 39 double redd = (rgb_readings[1] /gMax) * 255;
IonSystems 5:644bca33c1ca 40 double greend = (rgb_readings[2] /bMax) * 255;
IonSystems 5:644bca33c1ca 41 double blued = (rgb_readings[0] /rMax) * 255;
IonSystems 5:644bca33c1ca 42
IonSystems 5:644bca33c1ca 43 int red = redd;
IonSystems 5:644bca33c1ca 44 int green = greend;
IonSystems 5:644bca33c1ca 45 int blue = blued;
IonSystems 11:06f6e82b40a8 46 //colourDataAcquired = true;
IonSystems 5:644bca33c1ca 47 lcd->cls(); // clear display
IonSystems 5:644bca33c1ca 48 lcd->locate(0,0);
IonSystems 11:06f6e82b40a8 49 lcd->printf("R:%dG:%dB:%d",red,green,blue);
IonSystems 5:644bca33c1ca 50
IonSystems 5:644bca33c1ca 51 lcd->locate(1,0);
IonSystems 11:06f6e82b40a8 52 /*if(red > 55){
IonSystems 5:644bca33c1ca 53 lcd->printf("RED");
IonSystems 5:644bca33c1ca 54 }
IonSystems 5:644bca33c1ca 55 if(green > 55){
IonSystems 5:644bca33c1ca 56 lcd->printf("GREEN");
IonSystems 5:644bca33c1ca 57 }
IonSystems 5:644bca33c1ca 58 if(red < 30 && green > 30 && blue > 30){
IonSystems 5:644bca33c1ca 59 lcd->printf("BLUE");
IonSystems 11:06f6e82b40a8 60 }*/
IonSystems 5:644bca33c1ca 61
IonSystems 13:0661d658d9d1 62 bool redWithinThreshold[4] = {0,0,0,0};
IonSystems 13:0661d658d9d1 63 bool greenWithinThreshold[4]= {0,0,0,0};
IonSystems 13:0661d658d9d1 64 bool blueWithinThreshold[4]= {0,0,0,0};
IonSystems 5:644bca33c1ca 65 //Set red Thresholds
IonSystems 5:644bca33c1ca 66 redWithinThreshold[0] = (red >= redLT[0]) && (red <= redUT[0]);
IonSystems 5:644bca33c1ca 67 greenWithinThreshold[0] = (green >= redLT[1]) && (green <= redUT[1]);
IonSystems 5:644bca33c1ca 68 blueWithinThreshold[0] = (blue >= redLT[2]) && (blue <= redUT[2]);
IonSystems 5:644bca33c1ca 69 //Set green Thresholds
IonSystems 5:644bca33c1ca 70 redWithinThreshold[1] = (red >= greenLT[0]) && (red <= greenUT[0]);
IonSystems 5:644bca33c1ca 71 greenWithinThreshold[1] = (green >= greenLT[1]) && (green <= greenUT[1]);
IonSystems 5:644bca33c1ca 72 blueWithinThreshold[1] = (blue >= greenLT[2]) && (blue <= greenUT[2]);
IonSystems 5:644bca33c1ca 73 //Set blue Thresholds
IonSystems 5:644bca33c1ca 74 redWithinThreshold[2] = (red >= blueLT[0]) && (red <= blueUT[0]);
IonSystems 5:644bca33c1ca 75 greenWithinThreshold[2] = (green >= blueLT[1]) && (green <= blueUT[1]);
IonSystems 5:644bca33c1ca 76 blueWithinThreshold[2] = blue >= blueLT[2] && blue <= blueUT[2];
IonSystems 13:0661d658d9d1 77 //Set none Thresholds
IonSystems 13:0661d658d9d1 78 redWithinThreshold[3] = (red >= noneLT[0]) && (red <= noneUT[0]);
IonSystems 13:0661d658d9d1 79 greenWithinThreshold[3] = (green >= noneLT[1]) && (green <= noneUT[1]);
IonSystems 13:0661d658d9d1 80 blueWithinThreshold[3] = blue >= noneLT[2] && blue <= noneUT[2];
IonSystems 5:644bca33c1ca 81
IonSystems 5:644bca33c1ca 82 if(redWithinThreshold[0] && greenWithinThreshold[0] && blueWithinThreshold[0]){
IonSystems 5:644bca33c1ca 83 lcd->printf("RED");
IonSystems 13:0661d658d9d1 84 return RED;
IonSystems 5:644bca33c1ca 85 }
IonSystems 5:644bca33c1ca 86 else if(redWithinThreshold[1] && greenWithinThreshold[1] && blueWithinThreshold[1]){
IonSystems 5:644bca33c1ca 87 lcd->printf("GREEN");
IonSystems 13:0661d658d9d1 88 return GREEN;
IonSystems 5:644bca33c1ca 89 }
IonSystems 5:644bca33c1ca 90 else if(redWithinThreshold[2] && greenWithinThreshold[2] && blueWithinThreshold[2]){
IonSystems 5:644bca33c1ca 91 lcd->printf("BLUE");
IonSystems 13:0661d658d9d1 92 return BLUE;
IonSystems 13:0661d658d9d1 93 }
IonSystems 13:0661d658d9d1 94 else if(redWithinThreshold[3] && greenWithinThreshold[3] && blueWithinThreshold[3]){
IonSystems 13:0661d658d9d1 95 lcd->printf("NONE");
IonSystems 13:0661d658d9d1 96 return NONE;
IonSystems 5:644bca33c1ca 97 }
IonSystems 5:644bca33c1ca 98 else{
IonSystems 5:644bca33c1ca 99 lcd->printf("BIN");
IonSystems 13:0661d658d9d1 100 return BIN;
IonSystems 5:644bca33c1ca 101 }
IonSystems 13:0661d658d9d1 102
IonSystems 5:644bca33c1ca 103 }
IonSystems 5:644bca33c1ca 104
IonSystems 13:0661d658d9d1 105
IonSystems 13:0661d658d9d1 106