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@6:e64796f1f384, 2014-11-07 (annotated)
- Committer:
- IonSystems
- Date:
- Fri Nov 07 20:16:23 2014 +0000
- Revision:
- 6:e64796f1f384
- Parent:
- 5:644bca33c1ca
- Child:
- 11:06f6e82b40a8
Recovered from the attack of Euan
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 | 6:e64796f1f384 | 4 | TCS3472_I2C rgb_sensor(p28,p27); //p28 =sda, p27=scl |
IonSystems | 6:e64796f1f384 | 5 | |
IonSystems | 6:e64796f1f384 | 6 | int rgb_readings[4]; |
IonSystems | 6:e64796f1f384 | 7 | double rMax = 9244; |
IonSystems | 6:e64796f1f384 | 8 | double gMax = 3194; |
IonSystems | 6:e64796f1f384 | 9 | double bMax = 3590; |
IonSystems | 6:e64796f1f384 | 10 | |
IonSystems | 6:e64796f1f384 | 11 | //thresholds are in the RGB format. |
IonSystems | 6:e64796f1f384 | 12 | int redLT [3] = {79,23,41}; |
IonSystems | 6:e64796f1f384 | 13 | int redUT [3]= {92,28,49}; |
IonSystems | 6:e64796f1f384 | 14 | int greenLT [3] = {46,81,61}; |
IonSystems | 6:e64796f1f384 | 15 | int greenUT [3]= {60,107,81}; |
IonSystems | 6:e64796f1f384 | 16 | int blueLT [3]= {25,47,47}; |
IonSystems | 6:e64796f1f384 | 17 | int blueUT [3]= {28,52,52}; |
IonSystems | 6:e64796f1f384 | 18 | |
IonSystems | 6:e64796f1f384 | 19 | void initColourSensor(){ |
IonSystems | 6:e64796f1f384 | 20 | rgb_sensor.enablePowerAndRGBC(); |
IonSystems | 6:e64796f1f384 | 21 | rgb_sensor.setIntegrationTime(100); |
IonSystems | 6:e64796f1f384 | 22 | } |
IonSystems | 6:e64796f1f384 | 23 | |
IonSystems | 5:644bca33c1ca | 24 | Colour readColourSensor(){ |
IonSystems | 5:644bca33c1ca | 25 | rgb_sensor.getAllColors(rgb_readings); |
IonSystems | 5:644bca33c1ca | 26 | Colour colour; |
IonSystems | 5:644bca33c1ca | 27 | double redd = (rgb_readings[1] /gMax) * 255; |
IonSystems | 5:644bca33c1ca | 28 | double greend = (rgb_readings[2] /bMax) * 255; |
IonSystems | 5:644bca33c1ca | 29 | double blued = (rgb_readings[0] /rMax) * 255; |
IonSystems | 5:644bca33c1ca | 30 | |
IonSystems | 5:644bca33c1ca | 31 | int red = redd; |
IonSystems | 5:644bca33c1ca | 32 | int green = greend; |
IonSystems | 5:644bca33c1ca | 33 | int blue = blued; |
IonSystems | 5:644bca33c1ca | 34 | colourDataAcquired = true; |
IonSystems | 5:644bca33c1ca | 35 | lcd->cls(); // clear display |
IonSystems | 5:644bca33c1ca | 36 | lcd->locate(0,0); |
IonSystems | 5:644bca33c1ca | 37 | lcd->printf("R:%d G:%d B:%d",red,green,blue); |
IonSystems | 5:644bca33c1ca | 38 | |
IonSystems | 5:644bca33c1ca | 39 | lcd->locate(1,0); |
IonSystems | 5:644bca33c1ca | 40 | if(red > 55){ |
IonSystems | 5:644bca33c1ca | 41 | lcd->printf("RED"); |
IonSystems | 5:644bca33c1ca | 42 | } |
IonSystems | 5:644bca33c1ca | 43 | if(green > 55){ |
IonSystems | 5:644bca33c1ca | 44 | lcd->printf("GREEN"); |
IonSystems | 5:644bca33c1ca | 45 | } |
IonSystems | 5:644bca33c1ca | 46 | if(red < 30 && green > 30 && blue > 30){ |
IonSystems | 5:644bca33c1ca | 47 | lcd->printf("BLUE"); |
IonSystems | 5:644bca33c1ca | 48 | } |
IonSystems | 5:644bca33c1ca | 49 | |
IonSystems | 5:644bca33c1ca | 50 | bool redWithinThreshold[3] = {0,0,0}; |
IonSystems | 5:644bca33c1ca | 51 | bool greenWithinThreshold[3]= {0,0,0}; |
IonSystems | 5:644bca33c1ca | 52 | bool blueWithinThreshold[3]= {0,0,0}; |
IonSystems | 5:644bca33c1ca | 53 | //Set red Thresholds |
IonSystems | 5:644bca33c1ca | 54 | redWithinThreshold[0] = (red >= redLT[0]) && (red <= redUT[0]); |
IonSystems | 5:644bca33c1ca | 55 | greenWithinThreshold[0] = (green >= redLT[1]) && (green <= redUT[1]); |
IonSystems | 5:644bca33c1ca | 56 | blueWithinThreshold[0] = (blue >= redLT[2]) && (blue <= redUT[2]); |
IonSystems | 5:644bca33c1ca | 57 | //Set green Thresholds |
IonSystems | 5:644bca33c1ca | 58 | redWithinThreshold[1] = (red >= greenLT[0]) && (red <= greenUT[0]); |
IonSystems | 5:644bca33c1ca | 59 | greenWithinThreshold[1] = (green >= greenLT[1]) && (green <= greenUT[1]); |
IonSystems | 5:644bca33c1ca | 60 | blueWithinThreshold[1] = (blue >= greenLT[2]) && (blue <= greenUT[2]); |
IonSystems | 5:644bca33c1ca | 61 | //Set blue Thresholds |
IonSystems | 5:644bca33c1ca | 62 | redWithinThreshold[2] = (red >= blueLT[0]) && (red <= blueUT[0]); |
IonSystems | 5:644bca33c1ca | 63 | greenWithinThreshold[2] = (green >= blueLT[1]) && (green <= blueUT[1]); |
IonSystems | 5:644bca33c1ca | 64 | blueWithinThreshold[2] = blue >= blueLT[2] && blue <= blueUT[2]; |
IonSystems | 5:644bca33c1ca | 65 | |
IonSystems | 5:644bca33c1ca | 66 | if(redWithinThreshold[0] && greenWithinThreshold[0] && blueWithinThreshold[0]){ |
IonSystems | 5:644bca33c1ca | 67 | lcd->printf("RED"); |
IonSystems | 5:644bca33c1ca | 68 | colour = RED; |
IonSystems | 5:644bca33c1ca | 69 | } |
IonSystems | 5:644bca33c1ca | 70 | else if(redWithinThreshold[1] && greenWithinThreshold[1] && blueWithinThreshold[1]){ |
IonSystems | 5:644bca33c1ca | 71 | lcd->printf("GREEN"); |
IonSystems | 5:644bca33c1ca | 72 | colour = GREEN; |
IonSystems | 5:644bca33c1ca | 73 | } |
IonSystems | 5:644bca33c1ca | 74 | else if(redWithinThreshold[2] && greenWithinThreshold[2] && blueWithinThreshold[2]){ |
IonSystems | 5:644bca33c1ca | 75 | lcd->printf("BLUE"); |
IonSystems | 5:644bca33c1ca | 76 | colour = BLUE; |
IonSystems | 5:644bca33c1ca | 77 | } |
IonSystems | 5:644bca33c1ca | 78 | else{ |
IonSystems | 5:644bca33c1ca | 79 | lcd->printf("BIN"); |
IonSystems | 5:644bca33c1ca | 80 | colour = OTHER; |
IonSystems | 5:644bca33c1ca | 81 | } |
IonSystems | 5:644bca33c1ca | 82 | return colour; |
IonSystems | 5:644bca33c1ca | 83 | } |
IonSystems | 5:644bca33c1ca | 84 | |
IonSystems | 5:644bca33c1ca | 85 | void sendColourSignal(Colour colour){ |
IonSystems | 5:644bca33c1ca | 86 | switch(colour){ |
IonSystems | 5:644bca33c1ca | 87 | case RED: |
IonSystems | 5:644bca33c1ca | 88 | |
IonSystems | 5:644bca33c1ca | 89 | break; |
IonSystems | 5:644bca33c1ca | 90 | case GREEN: |
IonSystems | 5:644bca33c1ca | 91 | break; |
IonSystems | 5:644bca33c1ca | 92 | case BLUE: |
IonSystems | 5:644bca33c1ca | 93 | break; |
IonSystems | 5:644bca33c1ca | 94 | case OTHER: |
IonSystems | 5:644bca33c1ca | 95 | break; |
IonSystems | 5:644bca33c1ca | 96 | } |
IonSystems | 5:644bca33c1ca | 97 | } |