![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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@11:06f6e82b40a8, 2014-11-13 (annotated)
- Committer:
- IonSystems
- Date:
- Thu Nov 13 11:59:39 2014 +0000
- Revision:
- 11:06f6e82b40a8
- Parent:
- 6:e64796f1f384
- Child:
- 13:0661d658d9d1
Changed colour values for blue bottom plate
Who changed what in which revision?
User | Revision | Line number | New 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 | 11:06f6e82b40a8 | 22 | int redLT [3] = {211,0,0}; |
IonSystems | 11:06f6e82b40a8 | 23 | int redUT [3]= {400,140,200}; |
IonSystems | 11:06f6e82b40a8 | 24 | int greenLT [3] = {141,251,211}; |
IonSystems | 11:06f6e82b40a8 | 25 | int greenUT [3]= {210,400,400}; |
IonSystems | 11:06f6e82b40a8 | 26 | int blueLT [3]= {0,141,150}; |
IonSystems | 11:06f6e82b40a8 | 27 | int blueUT [3]= {140,250,210}; |
IonSystems | 6:e64796f1f384 | 28 | |
IonSystems | 6:e64796f1f384 | 29 | void initColourSensor(){ |
IonSystems | 6:e64796f1f384 | 30 | rgb_sensor.enablePowerAndRGBC(); |
IonSystems | 6:e64796f1f384 | 31 | rgb_sensor.setIntegrationTime(100); |
IonSystems | 6:e64796f1f384 | 32 | } |
IonSystems | 6:e64796f1f384 | 33 | |
IonSystems | 5:644bca33c1ca | 34 | Colour readColourSensor(){ |
IonSystems | 5:644bca33c1ca | 35 | rgb_sensor.getAllColors(rgb_readings); |
IonSystems | 5:644bca33c1ca | 36 | Colour colour; |
IonSystems | 5:644bca33c1ca | 37 | double redd = (rgb_readings[1] /gMax) * 255; |
IonSystems | 5:644bca33c1ca | 38 | double greend = (rgb_readings[2] /bMax) * 255; |
IonSystems | 5:644bca33c1ca | 39 | double blued = (rgb_readings[0] /rMax) * 255; |
IonSystems | 5:644bca33c1ca | 40 | |
IonSystems | 5:644bca33c1ca | 41 | int red = redd; |
IonSystems | 5:644bca33c1ca | 42 | int green = greend; |
IonSystems | 5:644bca33c1ca | 43 | int blue = blued; |
IonSystems | 11:06f6e82b40a8 | 44 | //colourDataAcquired = true; |
IonSystems | 5:644bca33c1ca | 45 | lcd->cls(); // clear display |
IonSystems | 5:644bca33c1ca | 46 | lcd->locate(0,0); |
IonSystems | 11:06f6e82b40a8 | 47 | lcd->printf("R:%dG:%dB:%d",red,green,blue); |
IonSystems | 5:644bca33c1ca | 48 | |
IonSystems | 5:644bca33c1ca | 49 | lcd->locate(1,0); |
IonSystems | 11:06f6e82b40a8 | 50 | /*if(red > 55){ |
IonSystems | 5:644bca33c1ca | 51 | lcd->printf("RED"); |
IonSystems | 5:644bca33c1ca | 52 | } |
IonSystems | 5:644bca33c1ca | 53 | if(green > 55){ |
IonSystems | 5:644bca33c1ca | 54 | lcd->printf("GREEN"); |
IonSystems | 5:644bca33c1ca | 55 | } |
IonSystems | 5:644bca33c1ca | 56 | if(red < 30 && green > 30 && blue > 30){ |
IonSystems | 5:644bca33c1ca | 57 | lcd->printf("BLUE"); |
IonSystems | 11:06f6e82b40a8 | 58 | }*/ |
IonSystems | 5:644bca33c1ca | 59 | |
IonSystems | 5:644bca33c1ca | 60 | bool redWithinThreshold[3] = {0,0,0}; |
IonSystems | 5:644bca33c1ca | 61 | bool greenWithinThreshold[3]= {0,0,0}; |
IonSystems | 5:644bca33c1ca | 62 | bool blueWithinThreshold[3]= {0,0,0}; |
IonSystems | 5:644bca33c1ca | 63 | //Set red Thresholds |
IonSystems | 5:644bca33c1ca | 64 | redWithinThreshold[0] = (red >= redLT[0]) && (red <= redUT[0]); |
IonSystems | 5:644bca33c1ca | 65 | greenWithinThreshold[0] = (green >= redLT[1]) && (green <= redUT[1]); |
IonSystems | 5:644bca33c1ca | 66 | blueWithinThreshold[0] = (blue >= redLT[2]) && (blue <= redUT[2]); |
IonSystems | 5:644bca33c1ca | 67 | //Set green Thresholds |
IonSystems | 5:644bca33c1ca | 68 | redWithinThreshold[1] = (red >= greenLT[0]) && (red <= greenUT[0]); |
IonSystems | 5:644bca33c1ca | 69 | greenWithinThreshold[1] = (green >= greenLT[1]) && (green <= greenUT[1]); |
IonSystems | 5:644bca33c1ca | 70 | blueWithinThreshold[1] = (blue >= greenLT[2]) && (blue <= greenUT[2]); |
IonSystems | 5:644bca33c1ca | 71 | //Set blue Thresholds |
IonSystems | 5:644bca33c1ca | 72 | redWithinThreshold[2] = (red >= blueLT[0]) && (red <= blueUT[0]); |
IonSystems | 5:644bca33c1ca | 73 | greenWithinThreshold[2] = (green >= blueLT[1]) && (green <= blueUT[1]); |
IonSystems | 5:644bca33c1ca | 74 | blueWithinThreshold[2] = blue >= blueLT[2] && blue <= blueUT[2]; |
IonSystems | 5:644bca33c1ca | 75 | |
IonSystems | 5:644bca33c1ca | 76 | if(redWithinThreshold[0] && greenWithinThreshold[0] && blueWithinThreshold[0]){ |
IonSystems | 5:644bca33c1ca | 77 | lcd->printf("RED"); |
IonSystems | 5:644bca33c1ca | 78 | colour = RED; |
IonSystems | 5:644bca33c1ca | 79 | } |
IonSystems | 5:644bca33c1ca | 80 | else if(redWithinThreshold[1] && greenWithinThreshold[1] && blueWithinThreshold[1]){ |
IonSystems | 5:644bca33c1ca | 81 | lcd->printf("GREEN"); |
IonSystems | 5:644bca33c1ca | 82 | colour = GREEN; |
IonSystems | 5:644bca33c1ca | 83 | } |
IonSystems | 5:644bca33c1ca | 84 | else if(redWithinThreshold[2] && greenWithinThreshold[2] && blueWithinThreshold[2]){ |
IonSystems | 5:644bca33c1ca | 85 | lcd->printf("BLUE"); |
IonSystems | 5:644bca33c1ca | 86 | colour = BLUE; |
IonSystems | 5:644bca33c1ca | 87 | } |
IonSystems | 5:644bca33c1ca | 88 | else{ |
IonSystems | 5:644bca33c1ca | 89 | lcd->printf("BIN"); |
IonSystems | 11:06f6e82b40a8 | 90 | colour = BIN; |
IonSystems | 5:644bca33c1ca | 91 | } |
IonSystems | 5:644bca33c1ca | 92 | return colour; |
IonSystems | 5:644bca33c1ca | 93 | } |
IonSystems | 5:644bca33c1ca | 94 | |
IonSystems | 5:644bca33c1ca | 95 | void sendColourSignal(Colour colour){ |
IonSystems | 5:644bca33c1ca | 96 | switch(colour){ |
IonSystems | 5:644bca33c1ca | 97 | case RED: |
IonSystems | 5:644bca33c1ca | 98 | |
IonSystems | 5:644bca33c1ca | 99 | break; |
IonSystems | 5:644bca33c1ca | 100 | case GREEN: |
IonSystems | 5:644bca33c1ca | 101 | break; |
IonSystems | 5:644bca33c1ca | 102 | case BLUE: |
IonSystems | 5:644bca33c1ca | 103 | break; |
IonSystems | 11:06f6e82b40a8 | 104 | case BIN: |
IonSystems | 5:644bca33c1ca | 105 | break; |
IonSystems | 5:644bca33c1ca | 106 | } |
IonSystems | 5:644bca33c1ca | 107 | } |